SelectedIndex Dropdown in DataGrid

G

Guest

Can someone please tell me who I get the selectedindex of a dropdown in a
datagrid???

I have the following code and it works but it doesn't select the correct
value when I edit the dropdown list!

Thanks


Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("SelectOffice", Myconn)
If e.Item.ItemType = ListItemType.EditItem Then

cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

Dim add_Office As DropDownList
Dim pageID = CInt(CType(e.Item.FindControl("pageID"),
TextBox).Text)

'Populates Office DropDownList with office names
add_Office = CType(e.Item.FindControl("DDLeditOffice"),
DropDownList)
add_Office.DataSource =
cmd.ExecuteReader(CommandBehavior.CloseConnection)
add_Office.DataTextField = "offName"
add_Office.DataValueField = "officeID"
add_Office.DataBind()
add_Office.SelectedIndex =
Myconn.Close()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top