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

Get Value from ItemCommand event when using ItemTemplate at MasterTableView

1 Answer 342 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TazDeveloper
Top achievements
Rank 1
TazDeveloper asked on 05 Jan 2012, 07:38 PM
I am working with a grid that I am using an ItemTemplate for the MasterTableView.  In addition to the ItemTemplate I have three GridButtonColumns.  When the user clicks one of these buttons, I want to get the Index of the record for that row (In my case the Unique Name is: AssetIdx).  

Without the ItemTemplate the following code works fine:

GridDataItem item;
String ArticleID;
 
item = e.Item as GridDataItem;
ArticleID = item["AssetIdx"].Text;


With the ItemTemplate the code does not work.

I saw the following note in the demos (http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/cardview/defaultcs.aspx) :

"When you set item template all GridDataItems/GridEditableColumns (auto-generated or declarative) will be replaced with a single cell which will be used as a container for the templated content."

I have looked everywhere, and I can't find an example to get the value when the grid is treated as a single cell.

Can someone point me in the correct direction.  Thanks!

1 Answer, 1 is accepted

Sort by
0
TazDeveloper
Top achievements
Rank 1
answered on 05 Jan 2012, 08:46 PM
Found my own answer.  I had to do two things:

1. Add DataKeyNames to MasterTableView tag

<MasterTableView        DataKeyNames="AssetIdx">

2. Reference this key in the code behind


 ArticleID = Convert.ToString(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["AssetIdx"]);

Tags
Grid
Asked by
TazDeveloper
Top achievements
Rank 1
Answers by
TazDeveloper
Top achievements
Rank 1
Share this question
or