This is a migrated thread and some comments may be shown as answers.

RadGrid - Definition for "Rows"

4 Answers 151 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wayne Christopherson
Top achievements
Rank 1
Wayne Christopherson asked on 07 May 2010, 04:20 PM
I receive the error "'Telerik.Web.UI.RadGrid' does not contain a definition for 'Rows' and no extension method 'Rows' accepting a first argument of type 'Telerik.Web.UI.RadGrid' could be found (are you missing a using directive or an assembly reference?)" when trying to iterate through the rows of a radgrid and get the values of a specific column. 

Essentially what I am trying to do is get all values for a specific column and put those values in a comma delimited list - this is done while the rad grid is being created...any help with that would be greatly appreciated.

Here is an example I used for a regular gridview prior to switching to a radgrid...

 

foreach (GridViewRow gvr in gvCustomerList.Rows)

 

{

sIen += gvr.Cells[0].Text +

",";

 

}


That seemed to work but since I have switched to using the RadGrid it doesn't.

Thanks!

Wayne Christopherson

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 07 May 2010, 04:51 PM
Hello Wayne,

I recommend you get the cells by name rather than by their index.

Sample code-snippet:
foreach (GridDataItem gvr in gvCustomerList.Items)
{
    //sIen += gvr.Cells[0].Text + ",";
    sIen += gvr["ColumnName"].Text + ","//recommended approach
}

For more information, please examine the following links:
Accessing cells and rows
Data items

Best regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Wayne Christopherson
Top achievements
Rank 1
answered on 07 May 2010, 07:35 PM
Thanks Daniel for the quick response...

Another issue that I am running across while trying to use this is that when I use your example I get ",,,,," yet when the grid is displayed I can clearly see the values...I am not sure if this matters or not but the column I am trying to get the values of is not a "GirdBoundColumn" it is a "GridTemplateColumn" with an "<asp:HyperLink" between the <ItemTemplate> tags as seen below: 

 

 

 

<telerik:GridTemplateColumn HeaderText="CustomerID" UniqueName="IEN" SortExpression="IEN_NUM" AutoPostBackOnFilter="true" HeaderStyle-Width="5%" ItemStyle-HorizontalAlign="left" HeaderStyle-HorizontalAlign="left" > 
    <ItemTemplate> 
        <asp:HyperLink ID="IEN" runat="server" Text='<%#Eval("IEN", "")%>' onclick='<%# Eval("IEN", "getWorksheet({0});") %>' ToolTip='<%#Eval("lockedby", "")%>' style="cursor:hand;" /> 
    </ItemTemplate> 
</telerik:GridTemplateColumn> 

Any suggestions as to how I can access that column and get the values that appear in that column for all the rows?

Thanks for you assistance.
Wayne

0
Daniel
Telerik team
answered on 11 May 2010, 09:54 PM
Hello Wayne,

In this case, you should get the text from the hyperlink rather than from the cell itself:
foreach (GridDataItem gvr in gvCustomerList.Items)
{
    HyperLink myHyperLink = gvr["IEN"].FindControl("IEN") as HyperLink;
    // gvr["Column Unique Name"].FindControl("Control ID")....
    sIen += myHyperLink.Text;
}

Best regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Wayne Christopherson
Top achievements
Rank 1
answered on 12 May 2010, 09:01 PM
Thanks again - that worked.
Tags
Grid
Asked by
Wayne Christopherson
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Wayne Christopherson
Top achievements
Rank 1
Share this question
or