SelectedIndex set in ItemDataBound Method but always index(0) set

G

Guest

Hi All,

I am beffudeled to say the least ...

I have code that dynamically populates drop down boxes (in a datagrid - edit
itme template) and sets the selectedindex in the dropdown to the equivalent
value in a DB.

For teams it works (I get the data from the DB) but or designation (game,
practice, exhibition) which I create as follows:

Dim drpD As DropDownList
drpD = CType(e.Item.FindControl("drpD"), DropDownList)
drpD.Items.Insert(0, "Game")
drpD.Items.Item(0).Value = "g"
drpD.Items.Insert(1, "Practice")
drpD.Items.Item(1).Value = "p"
drpD.Items.Insert(2, "Exhibition")
drpD.Items.Item(2).Value = "x"

If Trim(dsGame.Tables("Table").Rows(0).Item("Des").ToString()) =
"g" Then
drpD.SelectedIndex = 0
ElseIf
Trim(dsGame.Tables("Table").Rows(0).Item("Des").ToString()) = "p" Then
drpD.SelectedIndex = 1
Else
drpD.SelectedIndex = 2
End If
drpD.DataBind()

It always sets the selectedindex to 0. I have set some debug statemetns and
verrified that for an "x" game I go into the else statement. This should
mean that selected index is set to 2 but this does NOT happen.

Any help would be greatly appreciated.

Thank you,
 

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