Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown List with Grid in Edit Mode 1

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I'm using a dropdown list inside a gridview during edit mode. how do you set the dropdown list to pick up the value that's in the field you want to edit ?

Thanks

 
Good question, I was just working on the same code. This is what I did, but there may be better ways:
In the EditItemTemplate I put a literal and assigned the ID value to it i needed, and made it not visible(you can use any value you need):
Code:
 <asp:Literal ID="yourLiteral" runat="server" Text='<%# Eval("IDvalueYouNeed") %>'
        Visible="false"></asp:Literal>

Then in your code, use the RowDataBound:
Code:
If (e.Row.RowState = DataControlRowState.Edit) OrElse (e.Row.RowState = (DataControlRowState.Edit Or DataControlRowState.Alternate)) Then
            Dim id as Integer = DirectCast(e.Row.FindControl("yourLiteral").Text
            Dim ddl As DropDownList = DirectCast(e.Row.FindControl("YourDDL"), DropDownList)
            'Here, add or bind your dropdownlistvalues
            ddl.Items.FindByValue(id).Selected = True

This should get you going. Hope it helps.
 
Perfect, sorry for the late reply. This really helped me out.

Thanks again

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top