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

Access GridTemplateColumn?

3 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hans
Top achievements
Rank 1
Hans asked on 25 May 2012, 08:01 AM

How do I access a GridTemplateColumn in the Grid row that was clicked?

With the getDataKeyValue() method I can get the value of GridBoundColumns after defining the columns using the ClientDataKeyNames property of the MasterTableView.

But how can I get the value of GridTemplateColumns?

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 May 2012, 08:08 AM
Hello,

Try the following code in ItemCommand to access the values of template column on clicking the row.
C#:
void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "RowClick")
    {
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
            Label l = (Label)item.FindControl("Label1");
         }
     }
}

Thanks,
Shinu.
0
Hans
Top achievements
Rank 1
answered on 25 May 2012, 08:16 AM

Thanks, Shinu.

Unfortunately I forgot to mention that I need to do this on the client using JavaScript. Sorry about that.

I think I found a way, but it's not very elegant and I'm guessing there's a better way?

var masterTableView = sender.get_masterTableView();
var currentRow = args.get_itemIndexHierarchical();
var value = masterTableView.getCellByColumnUniqueName(masterTableView.get_dataItems()[currentRow], 'ColumnName').innerHTML;

0
Shinu
Top achievements
Rank 2
answered on 28 May 2012, 07:30 AM
Hello,

Try the following javascript to access label from client side.
JS:
<script type="text/javascript">
function OnRowClick(sender, args)
{
  var masterTable = sender.get_masterTableView();
  var row = masterTable.get_dataItems();
  for (var i = 0; i < row.length; i++)
  {
   var lbl = row[i].findElement('Label1');
  }
}
</script>

Thanks,
Shinu.
Tags
Grid
Asked by
Hans
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Hans
Top achievements
Rank 1
Share this question
or