Dropdown first Item
-
I have a form that deletes users, I use a a dropdown to select the user I want to delete(using SQL Server Database), I want the first element to be "Please select one of the following" How could it be? Regards
-
Add the item to the data source before populating the list, or use the
Insert
method of the list to insert an item after you have populated it.--- Year happy = new Year(2007);
Hi Dear Thanks alot for your reply give me a ststement how to use the insert method in my case, here i send you the code if needed: If Not IsPostBack Then conn1.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Hosting;Data Source=JICC" conn1.Open() Dim cm1 As New OleDbCommand("select * from Types", conn1) Dim ds1 As New DataSet Dim da1 As New OleDbDataAdapter Dim dr1 As OleDb.OleDbDataReader dr1 = cm1.ExecuteReader() If dr1.HasRows = False Then Label1.Text = "No records..." Label1.Visible = True DropDownList1.Enabled = False Button1.Enabled = False Else Dim cmd1 As New OleDbCommand("select * from Types order by t_name", conn1) da1.SelectCommand = cmd1 da1.Fill(ds1, "types") DropDownList1.DataTextField = "t_name" DropDownList1.DataValueField = "t_id" DropDownList1.DataSource = ds1.Tables(0).DefaultView DropDownList1.DataBind() da1.Dispose() End If End If
-
Hi Dear Thanks alot for your reply give me a ststement how to use the insert method in my case, here i send you the code if needed: If Not IsPostBack Then conn1.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Hosting;Data Source=JICC" conn1.Open() Dim cm1 As New OleDbCommand("select * from Types", conn1) Dim ds1 As New DataSet Dim da1 As New OleDbDataAdapter Dim dr1 As OleDb.OleDbDataReader dr1 = cm1.ExecuteReader() If dr1.HasRows = False Then Label1.Text = "No records..." Label1.Visible = True DropDownList1.Enabled = False Button1.Enabled = False Else Dim cmd1 As New OleDbCommand("select * from Types order by t_name", conn1) da1.SelectCommand = cmd1 da1.Fill(ds1, "types") DropDownList1.DataTextField = "t_name" DropDownList1.DataValueField = "t_id" DropDownList1.DataSource = ds1.Tables(0).DefaultView DropDownList1.DataBind() da1.Dispose() End If End If
-
ddlTitle.Items.Insert(0, New ListItem("Choose Title", "0")) put this after finishing data binding.