0% found this document useful (0 votes)
53 views1 page

Drop Down List

This code populates a drop down list with state data from a database table. It creates a SQL command to select all records from the state table, executes the command to get a data reader, clears any existing items from the drop down list, adds a "Select" option, then loops through the data reader to add each state's name and ID as a new list item to the drop down list.

Uploaded by

api-3848319
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views1 page

Drop Down List

This code populates a drop down list with state data from a database table. It creates a SQL command to select all records from the state table, executes the command to get a data reader, clears any existing items from the drop down list, adds a "Select" option, then loops through the data reader to add each state's name and ID as a new list item to the drop down list.

Uploaded by

api-3848319
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Retrieving contents 2 drop down list:

private void ddladdstate()


{
SqlCommand cmd = new SqlCommand("select * from state", cn);
SqlDataReader dr = cmd.ExecuteReader();
ddlstate.Items.Clear();
ddlstate.Items.Add("Select");
while (dr.Read())
{
ListItem li = new ListItem();
li.Value = dr["stateid"].ToString();
li.Text = dr["statename"].ToString();
ddlstate.Items.Add(li);
}
dr.Close();
}

You might also like