Gridview绑定中的下拉列表,用于Rowdatabound上的备用行

时间:2015-04-08 10:04:29

标签: asp.net vb.net gridview drop-down-menu rowdatabound

DropdownList gridview内的EditTemmplate RowDatabound 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 {{1}}但DropdlownList仅绑定备用行。例如,对于第一行它的绑定,而不是第二行,第三行是它,依此类推。以下是我的代码:

{{1}}

1 个答案:

答案 0 :(得分:1)

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

If ((e.Row.RowState And DataControlRowState.Edit) > 0)Then