标题:关于 ListBox.SelectedItem.Value问题
取消只看楼主
Theron
Rank: 1
等 级:新手上路
帖 子:127
专家分:0
注 册:2006-9-23
 问题点数:0 回复次数:2 
关于 ListBox.SelectedItem.Value问题

public partial class _Default : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
string conStr = ConfigurationManager.ConnectionStrings["mysqlconnection"].ConnectionString;
SqlConnection connection = new SqlConnection(conStr);
connection.Open();
string selectionStr = "SELECT * FROM Shippers";
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = selectionStr;
SqlDataReader dataReader = command.ExecuteReader();

while (dataReader.Read())
{
ListBox1.Items.Add(new ListItem(
dataReader[0] + " -- " + dataReader[1] + " -- " + dataReader[2],dataReader[0].ToString()));
}
dataReader.Close();
//this.Title = ListBox1.Text;
selectionStr = "SELECT * FROM Products";
command.CommandText = selectionStr;
dataReader = command.ExecuteReader();
ListBox2.DataSource = dataReader;
ListBox2.DataTextField = "ProductName";
ListBox2.DataValueField = "ProductID";
ListBox2.DataBind();

}
protected void Button1_Click(object sender, EventArgs e)
{

TextBox1.Text = ListBox2.SelectedItem.Text;
}



为什么 TextBox1.Text = ListBox2.SelectedItem.Text 这行代码在执行时出错?!
谢谢解答!

搜索更多相关主题的帖子: Value ListBox SelectedItem string connection 
2006-10-16 10:51
Theron
Rank: 1
等 级:新手上路
帖 子:127
专家分:0
注 册:2006-9-23
得分:0 
Object reference not set to an instance of an object.

2006-10-16 10:53
Theron
Rank: 1
等 级:新手上路
帖 子:127
专家分:0
注 册:2006-9-23
得分:0 
不是吧?!是偶表达有问题没人明白还是...其它原因啊!?

2006-10-18 16:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-96647-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034757 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved