我在rowdatabound fn中使用以下代码.
Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.Footer Then Dim ddlItem As DropDownList = CType(e.Row.FindControl("ddlFProjectLevels"), DropDownList) If ddlItem IsNot Nothing Then ddlItem.DataSource = objMileStone.GetProjectLevels() ddlItem.DataValueField = "MileStoneID" ddlItem.DataTextField = "Name" ddlItem.DataBind() End If End If If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.RowState = DataControlRowState.Edit Then Dim ddlEProjectLevels As DropDownList = CType(e.Row.FindControl("ddlEProjectLevels"), DropDownList) ddlEProjectLevels.DataSource = objMileStone.GetProjectLevels() ddlEProjectLevels.DataValueField = "MileStoneID" ddlEProjectLevels.DataTextField = "Name" ddlEProjectLevels.DataBind() ddlEProjectLevels.SelectedValue = milestoneid End If End If End Sub
ddlEProjectLevels是edititemtemplate中的dropdownlist.Whwn我在第1行单击编辑ddlEProjectLevels从数据库中加载数据.但是在第2行下拉列表中不包含values.Again在第3行它从备用行中的db.Means加载,当我点击编辑下拉列表时(ddlEProjectLevels)不加载值.任何人都可以帮忙吗?
与其他控件相比,此问题有点混乱,适用于GridView和DetailsView控件.您需要使用按位逻辑检查RowState枚举,因为项目可能具有Alternate或Edit状态.
所以代替:
If e.Row.RowState = DataControlRowState.Edit Then
尝试:
If (e.Row.RowState And DataControlRowState.Edit) > 0 Then
有关更多信息,请查看DataControlRowState Enumeration页面.