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

Get the value of a database column that is not shown in the grid

2 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
a
Top achievements
Rank 1
a asked on 12 Oct 2008, 08:00 AM
When databinding a grid to a SqlDataSource I'm wondering the best way to get the value of a database column that is not shown in the grid, but that is returned from the database for the corresponding row in the grid. 

I have a Delete GridButtonColumn that I want to show or hide for each row based on a value from the database. This type of column doesn't allow databinding, so I need to programmatically get at the database column value in the RadGrid ItemDataBound event to do the button hiding.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Oct 2008, 04:21 AM
Hi,

You can set the DataKeyName property of the grid as the required datafield and then retrieve its value as shown in the code below.
aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" > 
   <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="Age"
     ..... 

cs:
 if (e.Item is GridDataItem) 
        { 
          GridDataItem dataItem = (GridDataItem)e.Item;  
          string key = dataItem.GetDataKeyValue("Age").ToString();  
          // code to hide/show button 
        } 

Thanks
Princy.

0
a
Top achievements
Rank 1
answered on 18 Oct 2008, 02:43 AM

Thank you. Does modifying the DataKeyName value to include a column that is not part of the primary key impact insert/update/delete operations? I was thinking that the DataKeyName was only supposed to be the primary key of the database and that it was needed to enable this insert/update/delete functionality.

Tags
Grid
Asked by
a
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
a
Top achievements
Rank 1
Share this question
or