2009-07-07 38 views
1

我在rowdatabound fn中使用下面的代碼。Gridd的Rowdatabound

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.Whwn我點擊第一行ddlEProjectLevels編輯被加載的數據與來自database.But在第二排下拉列表中不包含values.Again在第三它被從備用db.Means裝行,當我點擊編輯dropdownlist(ddlEProjectLevels)doesnot加載values.Can任何人都可以幫忙?

回答

5

與其他控件相比,此問題有點令人困惑,並且適用於GridView和DetailsView控件。您需要使用按位邏輯檢查RowState枚舉,因爲項目可能有狀態爲Alternate或Edit。

所以不是:

If e.Row.RowState = DataControlRowState.Edit Then 

嘗試:

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

欲瞭解更多信息請查看DataControlRowState Enumeration頁面。

+0

它工作,感謝很多。 – user42348 2009-07-07 05:12:25