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

So easy it's ridiculous

4 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wardeaux
Top achievements
Rank 1
Wardeaux asked on 28 Aug 2008, 05:52 PM
Just one of those days...

i have a radgrid, first column is a record id that is not visible.  I want the user to select a row in the grid and then click an asp:button.  on the asp:button postback event i want to retrieve the record id from the selected grid row... sounds easy enough but for life of me can't find the solution...
many thanks!!!
wardeaux

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 29 Aug 2008, 04:23 AM
Hi,

Try accessing the selected row value in the button click event as shown below.

CS:
protected void Button1_Click1(object sender, EventArgs e) 
    { 
      foreach(GridDataItem item in RadGrid1.SelectedItems ) 
      { 
          string strID = item["IDColumnUniqueName"].Text; 
      } 
    } 


Thanks
Shinu.
0
Wardeaux
Top achievements
Rank 1
answered on 29 Aug 2008, 11:56 AM
PERFECT!!  You're the greatest!!
wardeaux
0
Accepted
Princy
Top achievements
Rank 2
answered on 29 Aug 2008, 12:28 PM
Hi Wardeaux,

One another suggestion will be to set the ID field as the DataKeyName and you can access its value in the click event of button.

ASPX:
<MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="ID"  CommandItemDisplay="top" > 
  

CS:
protected void Button1_Click1(object sender, EventArgs e)  
    {  
      foreach(GridDataItem item in RadGrid1.SelectedItems )  
      {  
          string strKey = item.GetDataKeyValue("ID").ToString(); 
      }  
    }  
 


Thanks
Princy.

0
Wardeaux
Top achievements
Rank 1
answered on 29 Aug 2008, 12:52 PM
Thanks, Princy!  That is also an EXCELLENT suggestion... I will be sure to add BOTH of these methods to my "bag of tricks"...  as it turns out i had already set the datamember for my hidden column to also be a datakeyname... now all i have to do is read its value!! 
it has been almost a year since I've used Radgrid and i'm VERY rusty... thanks to BOTH of you!!!
wardeaux
Tags
Grid
Asked by
Wardeaux
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Wardeaux
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or