This is a migrated thread and some comments may be shown as answers.
Finding Items in a Grid row on Button Click
4 Answers 52 Views
This is a migrated thread and some comments may be shown as answers.
gupta gf
Top achievements
Rank 1
gupta gf asked on 11 Nov 2009, 04:08 AM

      Hi,

                 In our project  many places we use RadControls. In that especially RadGrid is very frequent in use.
              For finding the RadGrid Selected row details( columns ) , we used to write like this as below
 
         This below radio button we placed in the ItemTemplate.

      <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn">
              <ItemTemplate>
                  <asp:RadioButton ID="rboAccount" runat="server" AutoPostBack="true" GroupName="myGroup"
                                                                            OnCheckedChanged="ToggleSelectedState" />
               </ItemTemplate>
      </telerik:GridTemplateColumn>

       foreach (GridDataItem item in rgSearchResults.MasterTableView.Items)
        {
            RadioButton radio = (RadioButton)item.FindControl("rboAccount");
            if (radio.Checked == true)
            {
                objCustomerContext.CustomerID = Convert.ToInt32(item.Cells[3].Text);
            }
        }

                       This works fine, but if maore records in the Grid, for finding the selected row details , it is taking more time. There is a      lot of performance issue.

         Can you please help me in this regard with a better performance oriented solution to find the values in the particular row.

 Thank you,
  Gupta

4 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 13 Nov 2009, 07:44 AM
Hi gupta gf,

Try using the SelectedItems collection of the RadGrid control.

I hope this helps.

Regards,
Tsvetoslav
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.
0
gupta gf
Top achievements
Rank 1
answered on 16 Nov 2009, 09:25 AM

  Hi Tsvetoslav,

               Thank you very much for your reply.
  
            My scenario is , I have a check box or link button in the ItemTemplate  . For finding the Grid Predefined columns like(GridCheckboxColumn or GridButtonColumn) or for Client side , ur solution will work.

Can you please help me out in this scenarion. I mentioned the code below.          


 <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn">
              <ItemTemplate>
                  <asp:RadioButton ID="rboAccount" runat="server" AutoPostBack="true" GroupName="myGroup"
                                                                            OnCheckedChanged="ToggleSelectedState" />
               </ItemTemplate>
      </telerik:GridTemplateColumn>

I have a set of rows. If any user selects particular Radiobutton then in the code (server side) i want to retrieve the Radio button selected rows information .
 
0
Princy
Top achievements
Rank 1
answered on 16 Nov 2009, 09:53 AM
Hi gupta,

Try out the following code wherein the NamingContainer(grid row) of the RadioButton is accessed on its CheckedChanged event:
c#:
protected void ToggleSelectedState(object sender, EventArgs e) 
    { 
        RadioButton rboAccount = (RadioButton)sender; 
        if (rboAccount.Checked) 
        { 
            GridDataItem dataItem = (GridDataItem)rboAccount.NamingContainer; 
            string strtxt = dataItem["BoundColumnUniqueName"].Text;            
        } 
    } 

Thanks
Princy.
0
gupta gf
Top achievements
Rank 1
answered on 16 Nov 2009, 10:24 AM
Hi princy,

          Thank you very much for Reply. The code which u have sent now will work if write in Checked changed event. at a time only one row details we can know from this. I have a scenario that , in a grid if user selects more than one row then for retrieving the Row details
i have written the below code

       foreach (GridDataItem item in rgSearchResults.MasterTableView.Items)
        {
            RadioButton radio = (RadioButton)item.FindControl("rboAccount");
            if (radio.Checked == true)
            {
                objCustomerContext.CustomerID = Convert.ToInt32(item.Cells[3].Text);
            }
        }


 From this I can get the all selected rows information.

 I think you have understood my problem.

  I am attaching the screen with this reply,

In that on Button Move to Selected account(s) , In Onclick event i have written the Above foreach loop.

 Instead of foreach, because it will take more execution time any other alternative to find the Selected rows information.

Thank you,
Gupta.K

Tags
Grid
Asked by
gupta gf
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
gupta gf
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Share this question
or