2013-02-14 2 views
1

У меня есть asp gridview, что я хочу заполнить элемент dropdownlist, когда выбранная строка переключается в режим редактирования.Dropdownlist в Gridview не заполняется во время режима редактирования

<EditItemTemplate> 
     <asp:DropDownList ID="ddlFormatID" runat="server"> 
     </asp:DropDownList> 

I'v гугле вокруг и я знаю, что вы, предполагают, чтобы сделать это в RowDataBound, а затем проверить, если строка является один редактируется, если да, то заполнить DDL, но я могу «т получить чек на строки, чтобы работать должным образом :(

 If DataControlRowState.Edit = e.Row.RowState Then 

     Dim ddlFormat As DropDownList = e.Row.FindControl("ddlFormatID") 
     ddlFormat.DataSource = XRefBCWorker.GetFormatCombos 
     ddlFormat.DataTextField = "Format" 
     ddlFormat.DataValueField = "FormatID" 
     ddlFormat.DataBind() 

    End If 

что я делаю неправильно?

+0

Попробуйте сделать это в RowEditing Event в GridView в. Также ознакомьтесь с http://msdn.microsoft.com/en-us/library/ie/ms178294.aspx –

ответ

0

вы можете бросить DataItem к типу, который вы отображения.

Protected Sub GridView_RowDataBound(sender As Object, e As GridViewRowEventArgs) 
    If DataControlRowState.Edit = e.Row.RowState Then 
     Dim item = e.Row.DataItem 
     Dim dr = DirectCast(item, DataRowView) 
     Dim id = Integer.Parse(dr(0).ToString()) 
    End If 
End Sub 
1

Я смог найти эту статью, и я изменил свой код в событии rowdatabound, и он сработал!

 If e.Row.RowType = DataControlRowType.DataRow Then 
     If e.Row.DataItem IsNot Nothing Then 
      If (e.Row.RowState And DataControlRowState.Edit) > 0 Then 
       Dim ddlFormat As DropDownList = e.Row.FindControl("ddlFormatID") 
       ddlFormat.DataSource = XRefBCWorker.GetFormatCombos 
       ddlFormat.DataTextField = "Format" 
       ddlFormat.DataValueField = "FormatID" 
       ddlFormat.DataBind() 
       ddlFormat.SelectedIndex = CurrentFormatID 
      End If 
     End If 
    End If 
+0

Я рад, что вы выяснили. Мне интересно, как вы получаете CurrentFormatID? – Win

0

Просто добавьте его в разметке:

<asp:DropDownList SelectedValue='<%# Bind("categoryId") %>'