Protected Sub GridViewC_Definition_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewC_Definition.RowDataBound
' 1. Retrieve reference from DropDownList
Dim C_ID As String
Dim GridViewTemplateC_ValuesDropDownList = TryCast(GridViewC_Definition.FindControl("DropDownListC_Values"), DropDownList)
' 2. Retrieve ID from each row
For Each row As GridViewRow In GridViewC_Definition.Rows
C_ID = row.Cells(0).Text
' 3. Reference from GetC_AttributesObjectDataSource
'GetC_Attributes.xxxx
'4. Assign ID from row and assign to the objectdatasource
GetC_Attributes.SelectParameters("C_ID").DefaultValue = C_ID
Next
'5. call data bind method from dropdownlist
'GridViewTemplateC_ValuesDropDownList.DataBind() <- if I include this i.e. remove the ' than an error appears: Object reference not set to an instance of an object.
End Sub
THe only problem is second row bind the ObjectDataSource the first results in the dropdownList are overwritten by the second bind and it goes on i.e. the third row assigns a value to the
ObjectDataSource and all DropDOwnLists (in the template field) are overwritten again.
polynaux
Member
195 Points
775 Posts
Re: Incorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated event
Jan 31, 2008 08:11 AM|LINK
THat is my latest "creation"
Protected Sub GridViewC_Definition_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewC_Definition.RowDataBound ' 1. Retrieve reference from DropDownList Dim C_ID As String Dim GridViewTemplateC_ValuesDropDownList = TryCast(GridViewC_Definition.FindControl("DropDownListC_Values"), DropDownList) ' 2. Retrieve ID from each row For Each row As GridViewRow In GridViewC_Definition.Rows C_ID = row.Cells(0).Text ' 3. Reference from GetC_AttributesObjectDataSource 'GetC_Attributes.xxxx '4. Assign ID from row and assign to the objectdatasource GetC_Attributes.SelectParameters("C_ID").DefaultValue = C_ID Next '5. call data bind method from dropdownlist 'GridViewTemplateC_ValuesDropDownList.DataBind() <- if I include this i.e. remove the ' than an error appears: Object reference not set to an instance of an object. End SubTHe only problem is second row bind the ObjectDataSource the first results in the dropdownList are overwritten by the second bind and it goes on i.e. the third row assigns a value to the
ObjectDataSource and all DropDOwnLists (in the template field) are overwritten again.
HOw can I avoid this overwriting ?
have a great day,
polynaux