0

DropdownListgridview其中 EditTemmplate绑定了RowDatabound. 但 DropdlownList 仅绑定备用行。例如,对于第一行,它的绑定,而不是第二行,第三行,等等。下面是我的代码:

 Protected Sub grvTdsMaster_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grvTdsMaster.RowDataBound
    Try
        lblErrorMsg.Visible = False
        lblErrorMsg.InnerText = ""
        If (e.Row.RowType = DataControlRowType.DataRow) Then

            If ((e.Row.RowState = DataControlRowState.Edit)) Then
                Dim ddlSection As DropDownList = e.Row.FindControl("ddlSection")
                Dim objTds As New TdsMasterDL
                Dim dt As New DataTable
                dt = objTds.GetTdsSectionName()
                ddlSection.DataSource = dt
                ddlSection.DataValueField = "TDS_Section_Id"
                ddlSection.DataTextField = "TDS_Section_Name"
                ddlSection.DataBind()

            End If
        End If
    Catch ex As Exception
        'Additional info that could be useful for debugging error
        Dim sb As New StringBuilder
        sb.Append("User=" & Session("username"))

        ExceptionHandler(ex, sb.ToString)
    End Try
End Sub
4

1 回答 1

1

我认为RowState默认情况下是备用的。检查MSDN上的 DataControlRowState 枚举。这应该适合你: -

If ((e.Row.RowState And DataControlRowState.Edit) > 0)Then
于 2015-04-08T10:18:59.880 回答