1

我有一个ASP GridView,我想在选定的行切换到编辑模式时填充下拉列表控件。

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

我已经用谷歌搜索了,我知道您应该在 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

我究竟做错了什么?

4

3 回答 3

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
于 2013-02-14T18:44:35.650 回答
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
于 2013-02-14T18:14:49.333 回答
0

只需将其添加到标记中:

<asp:DropDownList SelectedValue='<%# Bind("categoryId") %>'
于 2015-06-30T02:39:44.053 回答