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 这行代码在执行时出错?!
谢谢解答!