First DropDownlist load Data from Database,Then the first text in DropDownlist is "--Select--" Text.
ListItem li = new ListItem();
li.Text = "<--Select-->";
SqlDataAdapter ada = new SqlDataAdapter("select MOVIENAME,MOVIECODE from CURMOVI", conn);
DataTable dt = new DataTable();
ada.Fill(dt);
ddlMovieName.DataSource = dt;
ddlMovieName.DataTextField = "MOVIENAME";
ddlMovieName.DataValueField = "MOVIECODE";
ddlMovieName.DataBind();
ddlMovieName.Items.Insert(0, li);
******************************** (OR) ******************************
SqlDataAdapter ada = new SqlDataAdapter("select MOVIENAME,MOVIECODE from CURMOVI", conn);
DataTable dt = new DataTable();
ada.Fill(dt);
ddlMovieName.DataSource = dt;
ddlMovieName.DataTextField = "MOVIENAME";
ddlMovieName.DataValueField = "MOVIECODE";
ddlMovieName.DataBind();
ddlMovieName.Items[0].Text = "--Select--";
No comments:
Post a Comment