Hi,
Andy
ajw:'2. Create the command object, passing in the SQL string
Const strSQL As String = "SELECT PageID, PageName FROM Pages"
Dim myCommand As New SqlCommand(strSQL, myConnection)
myConnection.Open()
'3. Create the DataReader
Dim objDR As SqlDataReader
objDR = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
'Databind the DataReader to the listbox Web control
DropDownList1.DataSource = objDR
DropDownList1.DataBind()
'Add a new listitem to the beginning of the listitemcollection
DropDownList1.Items.Insert(0, New ListItem("-- Choose a Page --"))
If we use like following then???
----------------------------------
con.Open();
SqlCommand com = new SqlCommand("select * from Product", con);
Int32 i = 1;
ddlProduct.Items.Clear();
ddlProduct.Items.Add("--Select--");
ddlProduct.Items[0].Value = "0000";
dr = com.ExecuteReader();
while (dr.Read())
{
ddlProduct.Items.Add(dr[1].ToString());
ddlProduct.Items[i].Value = dr[0].ToString();
i = i + 1;
}
dr.Close();
con.Close();
con.Open()
Dim com As New SqlCommand("SELECT PageID, PageName FROM Pages",myConnection)
myConnection.Open()
Dim i As Int32 = 1
DropDownList1.Items.Clear()
DropDownList1.Items.Add("-- Choose a Page --")
DropDownList1.Items(0).Value = "0000"
Dim objDR As SqlDataReader
objDR = com.ExecuteReader(CommandBehavior.CloseConnection)
While objDR.Read()
DropDownList1.Items.Add(objDR(1).ToString())
DropDownList1.Items(i).Value = objDR(0).ToString()
i = i + 1
End While
objDR.Close()
Think about that both Data Text and Value fields are here.
Thanks..