I am attempting to iterate through a RadGrid and check the values of the checkbox inside a template column.
So far what I have is the following:
I get the error, "Reference to a non-shared member requires an object reference." On the line For Each myRow As GridDataItem In myGrid.Items. I have googled this, but come up with 0 results that either worked or made sense for me/my project. I am not quite sure how to get rid of this. I am pretty certain I am doing the iteration correctly. I have referenced a few posts on the Telerik forums as well as StackOverflow.
So far what I have is the following:
Protected Sub btnAssignToLocation_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnAssignToLocation.Click Try For Each myRow As GridDataItem In myGrid.Items Dim myID As String = myRow("ProductID").Text Dim myInLocation As CheckBox = CType(myRow.FindControl("cbLocationUsed"), CheckBox) If Not myInLocation Is Nothing Then If myInLocation.Checked Then MyData.ProcNonQuery("myQuery", "@LocID", lcLocation.LocationID, "@ID", myID) Else MyData.ProcNonQuery("myQuery", "@LocID", lcLocation.LocationID, "@ID", myID) End If PolicyPDFCache.ClearLocationCache(lcLocation.LocationID) End If Next Catch ex As Exception 'my error code End TryEnd SubI get the error, "Reference to a non-shared member requires an object reference." On the line For Each myRow As GridDataItem In myGrid.Items. I have googled this, but come up with 0 results that either worked or made sense for me/my project. I am not quite sure how to get rid of this. I am pretty certain I am doing the iteration correctly. I have referenced a few posts on the Telerik forums as well as StackOverflow.
6 Answers, 1 is accepted
0
Alexander
Top achievements
Rank 1
answered on 09 Jun 2014, 01:52 PM
For clarification, the button that I am clicking is not located inside the RadGrid. Its basically a sort of 'update' button that will save the changes in checkboxes that I have made.
0
Princy
Top achievements
Rank 2
answered on 10 Jun 2014, 04:41 AM
Hi Alexander,
I was not able to replicate such an issue at my end. Your code works fine. Please check the below sample code snippet. Provide your aspx code and the line which raises the error.
ASPX:
VB:
Thanks,
Princy
I was not able to replicate such an issue at my end. Your code works fine. Please check the below sample code snippet. Provide your aspx code and the line which raises the error.
ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1" AllowPaging="true" > <MasterTableView DataKeyNames="OrderID"> <Columns> <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" /> <telerik:GridTemplateColumn> <ItemTemplate> <asp:CheckBox ID="chkStatus" runat="server" /> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView></telerik:RadGrid><asp:Button ID="btnSave" runat="server" Text="Save" /><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind_newConnectionString3 %>" SelectCommand="SELECT * FROM [Orders]"></asp:SqlDataSource>VB:
Protected Sub btnSave_Click(sender As Object, e As System.EventArgs) Handles btnSave.Click Try For Each myRow As GridDataItem In RadGrid1.Items Dim myID As String = myRow("OrderID").Text Dim myInLocation As CheckBox = CType(myRow.FindControl("chkStatus"), CheckBox) If Not myInLocation Is Nothing Then If myInLocation.Checked Then myRow.ForeColor = Drawing.Color.Green Else myRow.ForeColor = Drawing.Color.Red End If End If Next Catch ex As Exception 'my error code End Try End SubThanks,
Princy
0
Alexander
Top achievements
Rank 1
answered on 10 Jun 2014, 01:44 PM
Hey Princy, thanks for responding!
The line errors on
The aspx for the graph/button is the following:
I don't see anything wrong with this current method and I really don't understand that error. FYI: I did leave out some information on the graph, but it was nonessential things.
The line errors on
For Each myRow As GridDataItem In myGrid.ItemsThe aspx for the graph/button is the following:
<td> <telerik:RadGrid runat="server" ID="myGrid" AllowFilteringByColumn="true" AllowPaging="true" PagerPosition="TopAndBottom" AllowSorting="true" PagerStyle-AlwaysVisible="true" MasterTableView-AllowMultiColumnSorting="true" PageSize="50" MasterTableView-ClientDataKeyNames="IDs" CurrentFilterFunction="Contains" GroupingSettings-CaseSensitive="false"> <MasterTableView AutoGenerateColumns="false"> <CommandItemSettings ShowExportToExcelButton="true" ShowExportToPdfButton="true" ShowAddNewRecordButton="false" ShowExportToWordButton="true" > </CommandItemSettings> <PagerStyle Position="TopAndBottom" /> <Columns> <telerik:GridBoundColumn FilterDelay="2000" ShowFilterIcon="false" DataField="ProductID" HeaderText="Product ID" SortExpression="ProductID" AutoPostBackOnFilter="true"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn HeaderText="In Loc" HeaderStyle-Width="55px" SortExpression="InLocation" HeaderStyle-ForeColor="White" AllowFiltering="false"> <ItemTemplate> <asp:CheckBox ID="cbLocationUsed" runat="server" Text="" Checked='<%# DataBinder.Eval(Container.DataItem, "InLocation")%>' /> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid></td><td valign="top"> <GraphBtn:WinampButton ID="btnAssignToLocation" runat="server" TemplateName="Save" Text="Update Location" />
</td>I don't see anything wrong with this current method and I really don't understand that error. FYI: I did leave out some information on the graph, but it was nonessential things.
0
Alexander
Top achievements
Rank 1
answered on 11 Jun 2014, 07:01 PM
I was able to establish that there is data in the column even though it is currently not being shown. This shouldn't be an issue in my opinion. I am going to attempt to just directly talk to the hlLink item instead.
0
Alexander
Top achievements
Rank 1
answered on 11 Jun 2014, 07:02 PM
Whoops, wrong forum post. my bad!
0
Alexander
Top achievements
Rank 1
answered on 12 Jun 2014, 01:38 PM
I changed my For Each line as someone told me and I was able to traverse it without the error.
My For Each line looks like:
My For Each line looks like:
For Each myRow As GridItem In myGrid.MasterTableView.GetItems(GridItemType.Item, GridItemType.AlternatingItem)