Search code examples
vb.netgridviewdrop-down-menufindcontrol

Set dropdownlist in gridview in rowediting event


Trying to get the findcontrol to work so I can set the default value of the dropdownlist I have in a template field, but I'm having no luck. Am I doing something wrong?

Dim drdList As DropDownList
    For Each row As GridViewRow In gridviewComputer.Rows

        drdList = gridviewComputer.Rows(e.NewEditIndex).FindControl("statusDropDown")


    Next

Solution

  • Found an easier way.

    Go into the gridview template editing, then under the EditItemTemplate, where I had the dropdownlist declared I selected Edit DataBindings. Refresh the Schema, then I was able to set the SelectedValue property to the corresponding field of my gridviews datasource. (Which really just fills in "Bind("columnName")" in the Code expression.) Problem solved!