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

[Solved] GridButtonColumn with id?

1 Answer 454 Views
Grid
This is a migrated thread and some comments may be shown as answers.
scrut
Top achievements
Rank 1
scrut asked on 20 May 2008, 05:31 PM
I have a Grid showing a set of files.
When the user clicks on the column with the filename, the Code-Behind does something with this information.

To do this, I have data-bound this Grid with a table function returning the attributes ID and NAME (among others).

Within the Grid, I created a GridButtonColumn like this:

<telerik:GridButtonColumn CommandName="Select" DataTextField="name" HeaderText="File name" Text="Select" UniqueName="column">  
    <HeaderStyle Width="200px" /> 
</telerik:GridButtonColumn> 

Now I wish to somehow make sure that when the User clicks on the link displayed within this column, the CodeBehind can obtain the ID associated with the displayed NAME.

How do I do that?

What event is thrown when a user clicks into the GridButtonColumn?
How can I link the ID to the column items? Making sure that it shows the name NAME was trivial via DataTextField. But what do I do with the ID?

Thanks

s.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 May 2008, 06:41 AM
Hi Scrut,

Try setting the required ID field as the DataKeyName and access it in the ItemCommand Event on clicking the GridButtonColumn as shown below.

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


CS:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
    {  
        GridDataItem item=(GridDataItem)e.Item;  
        if (e.CommandName == "Select")  
        {  
            string strKey = item.GetDataKeyValue("ID").ToString();  
        }  
 
    } 

Hope this helps..
Princy.

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