Incorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated eventhttp://forums.asp.net/t/1212875.aspx/1?Incorrect+method+signature+ObjectDataSource+funktionality+for+the+GridView+RowCreated+eventThu, 31 Jan 2008 17:27:30 -050012128752142144http://forums.asp.net/p/1212875/2142144.aspx/1?Incorrect+method+signature+ObjectDataSource+funktionality+for+the+GridView+RowCreated+eventIncorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated event <p>Hi Guys,<br> <br> I have the following littel sub that fires when GridView1 row created:<br> <br> &nbsp;</p> <pre class="prettyprint">Protected Sub xxxxx(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated Dim C_ID As String = GridView1.SelectedRow.Cells(0).Text GetC_AttributesObjectDataSource.InputParameters(&quot;C_ID&quot;) = C_ID GetC_AttributesObjectDataSource.DataBind() End Sub</pre>&nbsp;<br><br><br>The problem is, there is an error, as some of you may see <br>GetC_AttributesObjectDataSource.InputParameters("C_ID") = C_ID is the wrong part.<br><br>As an example, GetC_AttributesObjectDataSource.InputParameters("C_ID") = C_ID will only work with the<br>correct method signature which is:<br><br>&nbsp;&nbsp;<pre class="prettyprint"> <span class="kwd">Protected Sub</span> GetC_AttributesObjectDataSource_Selecting(<span class="kwd">ByVal</span> sender <span class="kwd">As Object</span>, <span class="kwd">ByVal</span> e <span class="kwd">As</span> System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) <span class="kwd">Handles</span> GetC_AttributesObjectDataSource.Selecting <span class="kwd">Dim</span> C_ID <span class="kwd">As String</span> = GridView1.SelectedRow.Cells(0).Text GetC_AttributesObjectDataSource.DataBind() e.InputParameters(<span class="st">"C_ID"</span>) = C_ID <span class="kwd">End Sub</span></pre>&nbsp;<br> <br> Well , the second one works but not on GridView1.RowCreated, instead it works with GetC_AttributesObjectDataSource.Selecting, which does not help me.<br> How can I do my proposed operation with the GridView1.RowCreated event?<br> <br> many thanks,<br> <br> polynaux 2008-01-30T10:44:37-05:002142302http://forums.asp.net/p/1212875/2142302.aspx/1?Re+Incorrect+method+signature+ObjectDataSource+funktionality+for+the+GridView+RowCreated+eventRe: Incorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated event <p>I'm not exactly sure what you're trying to do, but by the time the RowCreated event has fired, the GridView has already been bound to the ObjectDataSource. If you need to modify a Parameter of the ObjectDataSource, then the ObjectDataSource.Selecting event is the proper place for this.</p> 2008-01-30T12:30:41-05:002142335http://forums.asp.net/p/1212875/2142335.aspx/1?Re+Incorrect+method+signature+ObjectDataSource+funktionality+for+the+GridView+RowCreated+eventRe: Incorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated event <p>&nbsp;HI ecbruck !</p> <p>&nbsp;</p> <pre class="prettyprint">Protected Sub GridViewC_Definition_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load For Each row As GridViewRow In GridViewC_Definition.Rows DimC_ID As String C_ID = row.Cells(0).Text TextBox1.Text = C_ID GetC_AttributesObjectDataSource.Select() Next End Sub</pre><p>&nbsp; Let me explain again. As you can see here, as soon as the page loads my sub is iterating through the rows that are created by the gridview and gets the C_ID from each and</p><p>writes it into a textbox - this textbox is then used by my GetC_AttributesObjectDataSource (not shown) as the parameter required for the select() statement. <br>Unfortunately , the only ID in the textbox at the end is the one of the last row, because all the onces before are overwritten.&nbsp; and thats my problem.</p><p>&nbsp;</p><p>The same happens when I bind the whole think to the ObjectDataSource.Selecting method, as you proposed</p><p>&nbsp;</p><pre class="prettyprint"> <span class="kwd">Protected Sub</span> GetC_AttributesObjectDataSource_Selecting(<span class="kwd">ByVal</span> sender <span class="kwd">As Object</span>, <span class="kwd">ByVal</span> e <span class="kwd">As</span> System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) <span class="kwd">Handles</span> GetC_AttributesObjectDataSource.Selecting<br> <span class="kwd">Dim</span> C_ID <span class="kwd">As String</span> = GridView1.SelectedRow.Cells(0).Text<br> GetC_AttributesObjectDataSource.DataBind()<br> e.InputParameters(<span class="st">"C_ID"</span>) = C_ID<br> <span class="kwd">End Sub<br><br>Here, it does not even iterate through the rows, - which makes this method also ineffective because there is no iteration through each row.</span></pre><pre class="prettyprint">To conclude and built on your suggestion, I need to modify a Parameter of the ObjectDataSource, every time a GridView1 row is created (that is where the parameter comes from), then the<br>ObjectDataSource.Selecting event is the proper place for this. <br><br>PS: the parameter that feeds into the objectdatasource is then used to select specific information for each C_ID that was in the GridView1.Row (datakey)<br> </pre>&nbsp;&nbsp; 2008-01-30T12:49:15-05:002142383http://forums.asp.net/p/1212875/2142383.aspx/1?Re+Incorrect+method+signature+ObjectDataSource+funktionality+for+the+GridView+RowCreated+eventRe: Incorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated event <p>Sorry, but this just doesn't make any sense to me. In your example, you're firing off the Select method of the ObjectDataSource for every row in your GridView. This is highly ineffecient as you'd only see the results for the last row in your GridView both in your TextBox and the results of the secondary ObjectDataSource. You should only be data-binding to a particular ObjectDataSource once.</p> 2008-01-30T13:11:22-05:002142438http://forums.asp.net/p/1212875/2142438.aspx/1?Re+Incorrect+method+signature+ObjectDataSource+funktionality+for+the+GridView+RowCreated+eventRe: Incorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated event <p>Hi ecbruck,</p> <p>you are right, it would usually be efficient to fire the objectdatasource.select only once. but that is how my table/gridview looks:</p> <p><img src="http://metalray.redio.de/local/problemxxx1.JPG" height="385" width="661"><br> So I have to re-bind the GetC_AttributesObjectDataSource (which is the datasource for the DropDownList) everytime a row is created since it takes the freshly created C_ID as a paramter for the </p> <p>GetC_AttributesObjectDataSource that then fills the dropdownlist with the specific values for the specific C_ID.</p> <p>Or.....is there something I am not really aware about ?</p> <p>Thanks for your help,</p> <p>polynaux<br> &nbsp;</p> 2008-01-30T13:36:51-05:002142457http://forums.asp.net/p/1212875/2142457.aspx/1?Re+Incorrect+method+signature+ObjectDataSource+funktionality+for+the+GridView+RowCreated+eventRe: Incorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated event <p>I think I'm understanding what you're doing now. Each row has a DropDownList in it which is tied to one ObjectDataSource which is keyed off of the ID from each row. If this is the case, then you should move your code to the GridView.RowDataBound event. In that event, retireve a reference to your DropDownList and ObjectDataSource. Retrieve the ID from the row and assign it properly to your ObjectDataSource. Then, call the DataBind method of your DropDownList.</p> 2008-01-30T13:43:22-05:002142629http://forums.asp.net/p/1212875/2142629.aspx/1?Re+Incorrect+method+signature+ObjectDataSource+funktionality+for+the+GridView+RowCreated+eventRe: Incorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated event <p>&nbsp;Hi ecbruck !</p> <p>&nbsp;I have done it your way and came up with this sub:<br> </p> <p>&nbsp;</p> <pre class="prettyprint">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(&quot;DropDownListC_Values&quot;), 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(&quot;C_ID&quot;).DefaultValue = C_ID Next '5. call data bind method from dropdownlist 'GridViewTemplateC_ValuesDropDownList.DataBind() &lt;- if I include this i.e. remove the ' than an error appears: Object reference not set to an instance of an object. End Sub</pre><pre class="prettyprint">&nbsp;</pre><pre class="prettyprint">THe only problem now is that all the dropdownlists have the same value&nbsp;</pre>&nbsp;&nbsp; 2008-01-30T14:41:43-05:002144584http://forums.asp.net/p/1212875/2144584.aspx/1?Re+Incorrect+method+signature+ObjectDataSource+funktionality+for+the+GridView+RowCreated+eventRe: Incorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated event <p>THat is my latest &quot;creation&quot;</p> <p>&nbsp;</p> <pre class="prettyprint">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(&quot;DropDownListC_Values&quot;), 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(&quot;C_ID&quot;).DefaultValue = C_ID Next '5. call data bind method from dropdownlist 'GridViewTemplateC_ValuesDropDownList.DataBind() &lt;- if I include this i.e. remove the ' than an error appears: Object reference not set to an instance of an object. End Sub</pre> <p>&nbsp; <br> 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</p> <p>ObjectDataSource and all DropDOwnLists (in the template field) are overwritten again.</p> <p>HOw can I avoid this overwriting ?</p> <p>have a great day,</p> <p>polynaux&nbsp;</p> 2008-01-31T08:11:12-05:002145035http://forums.asp.net/p/1212875/2145035.aspx/1?Re+Incorrect+method+signature+ObjectDataSource+funktionality+for+the+GridView+RowCreated+eventRe: Incorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated event <p>The RowDataBound event is fired when every row in the GridView is DataBound so there's no need to further iterate through all of the rows. Do something more like this:&nbsp;<pre class="prettyprint">Protected Sub GridViewC_Definition_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewC_Definition.RowDataBound Dim gvr As GridViewRow = e.Row If gvr.RowType = DataControlRowType.DataRow Then Dim GridViewTemplateC_ValuesDropDownList = CType(gvr.FindControl(&quot;DropDownListC_Values&quot;), DropDownList) GetC_Attributes.SelectParameters(&quot;C_ID&quot;).DefaultValue = gvr.Cells(0).Text GridViewTemplateC_ValuesDropDownList.DataBind() End If End Sub</pre></p> 2008-01-31T12:22:45-05:002145780http://forums.asp.net/p/1212875/2145780.aspx/1?Re+Incorrect+method+signature+ObjectDataSource+funktionality+for+the+GridView+RowCreated+eventRe: Incorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated event <p>&nbsp;Hi ecbruck !</p> <p>Thanks for your suggestion. I would have never come up with this kind of code.</p> <p>Interestingly, the dropdownlist values are mixed up completely now. <br> <br> Whereas the DropDownList in Row 1 has the 2 values correct values &#43; the two values from the next row/DropDownList</p> <p>DropDownList in Row 2 has the 2 values from the first row, the correct values, &#43; the 2 values from row 3</p> <p>finally DropDownList in row 3 has the 3 values from row 2 and its own 2 correct values.</p> <p>How on earth can that be ?</p> <p>&nbsp;</p> <p><br> </p> <p>many thanks again,</p> <p>polynaux&nbsp;</p> <p>&nbsp;</p> <p>PS: the sql query works correctly <br> <br> PS2 : maybe the error has to do with the <br> </p> <pre class="prettyprint">...gvr.FindControl(&quot;DropDownListC_Values&quot;)... &lt;- since every dropdownlist in the rows is called &quot;DropDownListC_Values&quot;, and that is why they are added up (the values)</pre> 2008-01-31T16:28:18-05:002145849http://forums.asp.net/p/1212875/2145849.aspx/1?Re+Incorrect+method+signature+ObjectDataSource+funktionality+for+the+GridView+RowCreated+eventRe: Incorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated event <p>I think I might know what's going on. It appears as if the DataSourceControl you are tying to your is outside of the GridView. Correct? If so, you need to move this within the same template as your DropDownList.</p> 2008-01-31T16:55:20-05:002145936http://forums.asp.net/p/1212875/2145936.aspx/1?Re+Incorrect+method+signature+ObjectDataSource+funktionality+for+the+GridView+RowCreated+eventRe: Incorrect method signature: ObjectDataSource funktionality for the GridView.RowCreated event <p>Finally, thanks for the tip !</p> <p>Here is the solution that works (in case anyone in the future might be interested in this):</p> <p>&nbsp;&nbsp;</p> <pre class="prettyprint">Protected Sub GridViewC_Definition_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewC_Definition.RowDataBound Dim gvr As GridViewRow = e.Row If gvr.RowType = DataControlRowType.DataRow Then Dim GridViewTemplateC_ValuesDropDownList = CType(gvr.FindControl(&quot;DropDownListC_Values&quot;), DropDownList) Dim ods_CID_Values As ObjectDataSource = CType(e.Row.FindControl(&quot;GetC_Attributes&quot;), ObjectDataSource) ods_CID_Values.SelectParameters(&quot;C_ID&quot;).DefaultValue = gvr.Cells(0).Text GridViewTemplateC_ValuesDropDownList.DataBind() End If End Sub</pre> <p>&nbsp;After 4 days of work it is done.</p> <p>Thanks ecbruck.</p> <p>Have a great weekend.</p> <p>Polynaux&nbsp;</p> 2008-01-31T17:27:30-05:00