using (SqlConnection myConn = new SqlConnection(ConfigurationManager.ConnectionStrings["Database"].ToString()))
{
using (SqlCommand myCmd = new SqlCommand())
{
myConn.Open();
myCmd.Connection = myConn;
myCmd.CommandText = "SELECT ID, MODEL, FAMILY FROM Table ORDER BY SORT_ORDER ASC";
myCmd.CommandType = System.Data.CommandType.Text;
using (SqlDataReader myReader = myCmd.ExecuteReader())
{
DropDownListRemote.DataSource = myReader;
DropDownListRemote.DataTextField = "MODEL";
DropDownListRemote.DataValueField = "ID";
DropDownListRemote.DataBind();
DropDownListRemote.Items.Insert(0, new ListItem("--Select a Model--", "0"));
DropDownListRemote.SelectedIndex = 0;
}
}
}
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Feb 8, 2011, 1:37 PM
Suthish NairPosted Feb 7, 2011, 3:16 PM