I want to add a value to the drop down list that cannot be selected, like a title. Ex: I have a month drop down list. The very first item should be \"select month\" this sho
To add items to drop down list with value in asp.net using c# just add below codes for example:
try
{
SqlConnection conn = new SqlConnection(conStr);
SqlCommand comm = conn.CreateCommand();
comm = conn.CreateCommand();
comm.CommandText = "SELECT title,gid from Groups";
comm.CommandType = CommandType.Text;
conn.Open();
SqlDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
dropDownList.Items.Add(new
ListItem(dr[0].ToString(),dr[1].ToString()));
}
}
catch (Exception e)
{
lblText.Text = e.Message;
}
finally
{
conn.Close();
}