מצאתי את התשובה-כנסו להודעה-> <asp:ListBox id="ListBox1" runat="server" />
Then fill it in with a few lines in your code-behind — in the Page_Load, for example:
// "using System.Data.SqlClient;" at the top SqlCommand mySqlCommand = new SqlCommand(@"SELECT pub_id, pub_name FROM publishers ORDER BY pub_name", mySqlConnection); SqlDataReader myReader = mySqlCommand1.ExecuteReader(); ListBox1.DataSource = myReader; ListBox1.DataTextField = "pub_name"; ListBox1.DataValueField = "pub_id"; ListBox1.DataBind(); // here's how to preset the initial value ListBox1.SelectedValue = "1389"; myReader.Close(); mySqlCommand.Dispose();
1 תשובות
מצאתי את התשובה-כנסו להודעה->
<asp:ListBox id="ListBox1" runat="server" />
Then fill it in with a few lines in your code-behind — in the Page_Load, for example:
// "using System.Data.SqlClient;" at the top
SqlCommand mySqlCommand = new SqlCommand(@"SELECT pub_id, pub_name
FROM publishers
ORDER BY pub_name", mySqlConnection);
SqlDataReader myReader = mySqlCommand1.ExecuteReader();
ListBox1.DataSource = myReader;
ListBox1.DataTextField = "pub_name";
ListBox1.DataValueField = "pub_id";
ListBox1.DataBind();
// here's how to preset the initial value
ListBox1.SelectedValue = "1389";
myReader.Close();
mySqlCommand.Dispose();