Forum Moderators: open

Message Too Old, No Replies

Drop Down List

         

zxk105

9:36 pm on Mar 22, 2005 (gmt 0)

10+ Year Member



I am using a DataGrid to edit and update the data in my database. I am using a preset Drop Down List in one of my Template Columns. So the problem I have now is when I am in the "edit state" and my text boxes and drop down list show up, the selected item in the drop down list is the first one. However, I want the selected item to correspond to the one already saved in the database. I hope I made it clear enough.....How can I do this?

CaseyRyan

10:01 pm on Mar 22, 2005 (gmt 0)

10+ Year Member



I don't have the specific code, but I found an example online:

Go Here [developer.com] for the example.

Basically when you hit edit, you set the editItemIndex and retrieve that row of data. You do a findcontrol to get teh dropdown and then do a findbyvalue with the value from the non-edit row.

-=casey=-

zxk105

6:51 pm on Mar 23, 2005 (gmt 0)

10+ Year Member



It worked! Thanks for the code. At first it wasn't working b/c I was using the shortcut:

Dim ddlSetIndex as DropDownList = E.Item.FindControl("ddlPicID")

Instead of:

Dim ddlSetIndex As DropDownList = CType(DBEditDataGrid.Items(DBEditDataGrid.EditItemIndex).FindControl("ddlPicID"), DropDownList)

Why was I getting an error? What is the difference between the two lines? I'm just wondering so I can learn a bit more.....thanks.......