Hi,

I am having an issue where i want to be able to read the value of a particular cell from a selected row in telerik radgrid.

I am using the following code:

<%@ Page Language="C#" MasterPageFile="~/Page.master" AutoEventWireup="true" CodeFile="ProductSignup.aspx.cs" Inherits="ProductSignup" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style2
        {
            width: 100%;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <table class="style2">
        <tr>
            <td>
                <asp:Panel ID="Panel1" runat="server" Height="416px">
                    Select A Product Type:<br />
                    <asp:RadioButton ID="rdPersonal" runat="server" AutoPostBack="True" 
                        GroupName="G2" oncheckedchanged="rdPersonal_CheckedChanged" 
                        Text="Personal Drives" />
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:RadioButton ID="rdBusiness" runat="server" AutoPostBack="True" 
                        GroupName="G2" oncheckedchanged="rdBusiness_CheckedChanged" 
                        Text="Business Drive" />
                    <br />
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:Cloud %>" 
                        SelectCommand="SELECT * FROM [CLOUD_ITEM_MST] WHERE ([item_id] LIKE '%' + @item_id + '%') ORDER BY [item_price_Iy]">
                        <SelectParameters>
                            <asp:SessionParameter Name="item_id" SessionField="drive type" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" 
                        CellSpacing="0" DataSourceID="SqlDataSource1" GridLines="None" 
                        Width="577px" AllowSorting="True" ShowGroupPanel="True">
                        <FilterMenu EnableImageSprites="False">
                        </FilterMenu>
                        <ClientSettings allowdragtogroup="True">
                            <Selecting AllowRowSelect="True" CellSelectionMode="None" />
                        </ClientSettings>
                        <MasterTableView AutoGenerateColumns="False" DataKeyNames="item_id" 
                            DataSourceID="SqlDataSource1" allowsorting="False">
                            <CommandItemSettings ExportToPdfText="Export to PDF" />
                            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" 
                                Visible="True">
                                <HeaderStyle Width="20px" />
                            </RowIndicatorColumn>
                            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" 
                                Visible="True">
                                <HeaderStyle Width="20px" />
                            </ExpandCollapseColumn>
                            <Columns>
                                <telerik:GridBoundColumn DataField="item_id" 
                                    FilterControlAltText="Filter item_id column" HeaderText="item_id" 
                                    ReadOnly="True" SortExpression="item_id" UniqueName="item_id">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="item_name" 
                                    FilterControlAltText="Filter item_name column" HeaderText="item_name" 
                                    SortExpression="item_name" UniqueName="item_name">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="item_price_Iy" DataType="System.Double" 
                                    FilterControlAltText="Filter item_price_Iy column" HeaderText="item_price_Iy" 
                                    SortExpression="item_price_Iy" UniqueName="item_price_Iy">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="item_price_2y" DataType="System.Double" 
                                    FilterControlAltText="Filter item_price_2y column" HeaderText="item_price_2y" 
                                    SortExpression="item_price_2y" UniqueName="item_price_2y">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="item_price_3y" 
                                    FilterControlAltText="Filter item_price_3y column" HeaderText="item_price_3y" 
                                    SortExpression="item_price_3y" UniqueName="item_price_3y">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="item_max_users" DataType="System.Double" 
                                    FilterControlAltText="Filter item_max_users column" HeaderText="item_max_users" 
                                    SortExpression="item_max_users" UniqueName="item_max_users">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="item_size" DataType="System.Double" 
                                    FilterControlAltText="Filter item_size column" HeaderText="item_size" 
                                    SortExpression="item_size" UniqueName="item_size">
                                </telerik:GridBoundColumn>
                            </Columns>
                            <EditFormSettings>
                                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                </EditColumn>
                            </EditFormSettings>
                        </MasterTableView>
                    </telerik:RadGrid>
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
                    <br />
                </asp:Panel>
            </td>
            <td>
                <asp:Panel ID="Panel2" runat="server">
                </asp:Panel>
            </td>
        </tr>
    </table>
</asp:Content>

c# code behind is as follows:

protected void Button1_Click(object sender, EventArgs e)
    {
        string s3;
        foreach (GridDataItem selectinganItem in RadGrid1.MasterTableView.Items)
        {
            if (selectinganItem.Selected)
            {
                Label1.Text = selectinganItem["item_price_iy"].Text;
            }
        }
    }

Whenever i select a row and click on the button - the label1.text does not change. In debugging it shows that the radgrid row selected value is always false.

I used similar code elsewhere in my site and it works fine.

Please help.

Member Avatar for LastMitch

Whenever i select a row and click on the button - the label1.text does not change. In debugging it shows that the radgrid row selected value is always false.

I am assuming you are using this:

http://demos.telerik.com/aspnet-ajax/grid/examples/client/selecting/defaultcs.aspx

I don't know what is string s3?

Read this:

http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

For your button that goes with the link above:

protected void Button1_Click(object sender, EventArgs e)
   {
       foreach (GridDataItem item in RadGrid1.MasterTableView.SelectedItems) 
       {
           string name = item["item_price_iy"].Text;
       }
   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.