Rowdatabound 上交替行的 gridview 绑定中的下拉列表
Dropdown list inside gridview binding for alternate rows on Rowdatabound
我在 gridview
中有 DropdownList
在 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
我认为 RowState
默认是备用的。检查 MSDN 上的 DataControlRowState 枚举。这应该适合你:-
If ((e.Row.RowState And DataControlRowState.Edit) > 0)Then
我在 gridview
中有 DropdownList
在 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
我认为 RowState
默认是备用的。检查 MSDN 上的 DataControlRowState 枚举。这应该适合你:-
If ((e.Row.RowState And DataControlRowState.Edit) > 0)Then