2013-02-14 80 views
1

我有一個asp gridview,我想填充下拉列表控件,當選定的行切換到編輯模式。Gridview中的下拉列表不在編輯模式下填充

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

心中已經GOOGLE了四周,我知道你想這樣做在的RowDataBound,然後檢查是否該行正在編輯的一個,如果這樣的話填充DDL,但我可以「T獲得檢查該行正常工作:(

 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

嘗試在GridView的RowEditing事件做。另外請查看http://msdn.microsoft.com/en-us/library/ie/ms178294.aspx – 2013-02-14 17:51:45

回答

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 2013-02-15 19:39:46

0

只需添加它的標記:

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