radgrid- getting selected rows value.

1 Answer 4192 Views
Grid
Dhana R
Top achievements
Rank 1
Dhana R asked on 25 Jul 2009, 05:57 AM
hi,


i am using check box to select one row or multiple rows in the grid. I would like to get the key value(Id) for multiple selected rows in an On Click event of a button. The button is not part of the grid.

plz help me

i used this belwo code.in aspx file
 <telerik:RadGrid Width="50%" ID="RadGrid1" runat="server"
        AllowPaging="True" AllowSorting="True"  GridLines="None"     
        ShowFooter="True" AllowAutomaticInserts="True"
        AllowAutomaticUpdates="True" ShowStatusBar="True"  
        AutoGenerateColumns="False"
        ondeletecommand="RadGrid1_DeleteCommand"
        oninsertcommand="RadGrid1_InsertCommand"
        onupdatecommand="RadGrid1_UpdateCommand"
       
         AllowMultiRowSelection="True"
        Skin="Web20" ondetailtabledatabind="RadGrid1_DetailTableDataBind"
        onneeddatasource="RadGrid1_NeedDataSource" onselectedindexchanged="RadGrid1_SelectedIndexChanged"   
        >
  ....
       ......
         
 <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn">
                            <HeaderStyle Width="30px"></HeaderStyle>
                            <HeaderTemplate>
                             <asp:CheckBox id="headerChkbox" OnCheckedChanged="ToggleSelectedState" AutoPostBack="True" runat="server"></asp:CheckBox>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox id="Chkitem" OnCheckedChanged="ToggleRowSelection" AutoPostBack="True" runat="server"></asp:CheckBox>
                            </ItemTemplate>
                     </telerik:GridTemplateColumn>
                        ....
                       ......

<tellerik:radGrid>

 </telerik:RadGrid>
   
    <asp:Button ID="Button1"  runat="server" Text="Get" onclick="Button1_Click" />



        
in the button click event, i have to get the selected rows values.

i can get the count using radGrid1.SelectedItems.

plz guide me how to get the id value for selected rows

Thanks,
Dhana
Amit
Top achievements
Rank 1
commented on 07 Sep 2012, 12:50 PM

hii

  How to select row in telerik RadGrid and get value of row .

Thanks
Amit

Steve
Top achievements
Rank 1
commented on 07 Sep 2012, 03:05 PM

This is the sort of stuff I'm doing and it works fine.

            foreach (GridDataItem item in RadGrid.SelectedItems)
            {
                some variable here = item["XXXXX"].Text;
            }

just substitute the column name you want the value of in place of the XXXX above.
Hope that helps
Amit
Top achievements
Rank 1
commented on 08 Sep 2012, 10:34 AM

hii thanks for reply
i have used  this code but some times an error occur how can solved it. it's shown here "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index".
and have u an idea  for this problem solve . than please tell me..

Thanks
Amit

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Jul 2009, 04:27 AM
Hi Dhana R,

Try the following code anippet in order ti get the selected value from code behind.

C#:
 
protected void Button1_Click(object sender, EventArgs e) 
{         
    foreach(GridDataItem item in RadGrid1.SelectedItems) 
    { 
        Response.Write(item["CustomerID"].Text.ToString()); // CustomerID is the uniquename of column 
        string custoID = item.GetDataKeyValue("CustomerID"); // Works if you set the DataKeyValue as CustomerID 
    } 

-Shinu.
Dhana R
Top achievements
Rank 1
commented on 29 Jul 2009, 08:34 AM

Thanks for your reply.Its working

Thanks,
Dhana
Abdul Kadar
Top achievements
Rank 1
commented on 03 Oct 2009, 10:28 AM

Hi shinu,

How to write this code using vb.
Thanks for ur help.
Regards
Kadar
Nikolay Rusev
Telerik team
commented on 05 Oct 2009, 06:08 AM

Hello Kadar,

You can use
http://converter.telerik.com/ to convert C# to VB.

Greetings,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Amit
Top achievements
Rank 1
commented on 07 Sep 2012, 12:50 PM

.
Tags
Grid
Asked by
Dhana R
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or