3
Answers

Telerik RadGrid

Jose Saiz

Jose Saiz

7y
166
1
Does any one have a sample of the Telerik RadGrid that I am able to select the a row from the grid and get the real value from the selected row?
 
I have tried all samples and neither one can help, when I don't get an error I get the wrong value from the selected row.
 
This is what I've been trying (default.aspx)
  1. <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" DataSourceID="SqlDataSource2" AllowSorting="True"                  
  2.                 PageSize="7" AllowPaging="True" runat="server" OnSortCommand="RadGrid1_SortCommand"  
  3.                 OnPageIndexChanged="RadGrid1_PageIndexChanged"  OnPageSizeChanged="RadGrid1_PageSizeChanged" OnEditCommand="RadGrid1_EditCommand">                  
  4.                 <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>  
  5.                 <MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataSourceID="SqlDataSource2"  
  6.                     DataKeyNames="logId" AutoGenerateColumns="false" InsertItemDisplay="Top"  
  7.                     InsertItemPageIndexAction="ShowItemOnFirstPage">  
  8.                     <Columns>                        
  9.                         <telerik:GridButtonColumn DataTextField="logId" CommandName="Edit">  
  10.                         </telerik:GridButtonColumn>                            
  11.                         <telerik:GridBoundColumn DataField="log_date" UniqueName="log_date" HeaderText="Date">  
  12.                         </telerik:GridBoundColumn>  
  13.                         <telerik:GridBoundColumn DataField="log_type" UniqueName="log_type" HeaderText="Type">  
  14.                         </telerik:GridBoundColumn>  
  15.                         <telerik:GridBoundColumn DataField="client_name" UniqueName="client_name" HeaderText="Client Name">  
  16.                         </telerik:GridBoundColumn>  
  17.                         <telerik:GridBoundColumn DataField="delivery_method" UniqueName="delivery_method" HeaderText="Method">  
  18.                         </telerik:GridBoundColumn>  
  19.                         <telerik:GridBoundColumn DataField="entered_by" UniqueName="entered_by" HeaderText="Entered By">  
  20.                         </telerik:GridBoundColumn>  
  21.                         <telerik:GridBoundColumn DataField="facility_name" UniqueName="facility_name" HeaderText="Facility">  
  22.                         </telerik:GridBoundColumn>  
  23.                         <telerik:GridBoundColumn DataField="log_status" UniqueName="log_status" HeaderText="Status">  
  24.                         </telerik:GridBoundColumn>  
  25.                         <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">  
  26.                         </telerik:GridButtonColumn>  
  27.                     </Columns>  
  28.                 </MasterTableView>  
  29.                   
  30.              </telerik:RadGrid>  
  31.              <asp:SqlDataSource ID="SqlDataSource2" runat="server"></asp:SqlDataSource>  
 default.aspx.cs (Code behind)
  1. protected void LogDailyLogDataListing()  
  2.     {  
  3.         
  4.         SqlDataSource2.ConnectionString = "Connection String Here"  
  5.         SqlDataSource2.SelectCommand = "select * from table";  
  6.         this.RadGrid1.DataBind();  
  7.     }   
  8.  protected void RadGrid1_EditCommand(object sender, EventArgs e)          
  9.     {  
  10.         //- Per Telerik sample this suppose to work but it does not.  
  11.         foreach (var item in RadGrid1.SelectedItems)  
  12.         {  
  13.             if (item is GridDataItem)  
  14.             {  
  15.                 GridDataItem dataItem = item as GridDataItem; // found the   
  16.                string sLogId = dataItem["logId"]; // found the cell  
  17.             }  
  18.         }  
  19.     }  
  20.     protected void RadGrid1_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)  
  21.     {  
  22.         LogDailyLogDataListing();  
  23.     }  
  24.   
  25.     protected void RadGrid1_PageIndexChanged(object sender, Telerik.Web.UI.GridPageChangedEventArgs e)  
  26.     {  
  27.         LogDailyLogDataListing();  
  28.     }  
  29.   
  30.     protected void RadGrid1_SortCommand(object sender, Telerik.Web.UI.GridSortCommandEventArgs e)  
  31.     {  
  32.         LogDailyLogDataListing();  
  33.     }  
I will appriciate the help and sample code very much. 
 
Thanks 
Answers (3)
0
Jose Saiz

Jose Saiz

NA 107 7.2k 7y
Finally I got it to work thanks to a telerik old employee, who helped a lot
this is what he suggested, to replace the OnEditCommand for the following in the 
 
Default.aspx 
  1. OnItemCommand="RadGrid1_ItemCommand" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged"   
 Default.aspx.cs (Code behind)
  1.  protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
  2.     {  
  3.         if (e.CommandName == RadGrid.SelectCommandName)  
  4.         {  
  5.             string sSelectedRowValue = "Primary key for the clicked item from ItemCommand: " + (e.Item as GridDataItem).GetDataKeyValue("logId").ToString();   
  6.         }  
  7. }  
  8. protected void RadGrid1_SelectedIndexChanged(object sender, System.EventArgs e)  
  9.     {  
  10.         //- This gives me the row selected from the RadGrid
  11.         Response.Write("Primary key for the clicked item from SelectedIndexChanged: "          
  12.         + (RadGrid1.SelectedItems[0] as GridDataItem).GetDataKeyValue("logId").ToString();  
  13. }  
 Thank you all for all your help
 
0
Jose Saiz

Jose Saiz

NA 107 7.2k 7y
Thanks Sagar for your reply, I have tried all sample from Telerik FAQ, Knowledge base etc.
and neither one help, all I want to accomplish is to select the primary Id items from the RadGrid and use it in another page that does not contain the RadGrid control, I was only able to make it to work using the Edit template and view the selected row within the same page that has the RadGrid control, but it is not what I am looking for.
 
I thought the Telerik RadGrid was more friendly, it appears to only works with its own template.
 
Thanks again. 
0
Sagar  Pandurang Kap

Sagar Pandurang Kap

NA 2.7k 7.5k 7y
Hi,
try below link :-
 
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/Selecting/getting-cell-values-for-selected-rows
 
It might helps...