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

[Solved] How to know the value of a column?

4 Answers 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luis
Top achievements
Rank 1
Luis asked on 26 Nov 2009, 03:34 PM
Hello

I have a RadGrid with a template column(imagebutton)

i want
  when i click the imagebutton execute a code behind

but i need to know a column value for Example.: an email

how can i do that?


Thanks

P.S.
Sorry about my english is not good enough :)

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 26 Nov 2009, 04:24 PM
Hello Luis,

Try this approach:
<telerik:GridTemplateColumn UniqueName="Test">
    <ItemTemplate>
        <asp:ImageButton ID="ImageButton1" runat="server" OnClientClick="getValues(this)"
            ImageUrl="~/img.png" AlternateText="Button" />
    </ItemTemplate>
</telerik:GridTemplateColumn>

<script type="text/javascript">
    function getValues(sender)
    {
        var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
        var columnIndex = masterTable.getColumnByUniqueName("myColumnName").get_element().cellIndex;
        var cell = sender.parentNode;
        var text = cell.parentNode.cells[columnIndex].innerHTML;
        alert(text);
    }
</script>

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Luis
Top achievements
Rank 1
answered on 27 Nov 2009, 01:05 PM
Is ok
but i want to do this from VB or C#


0
Accepted
Daniel
Telerik team
answered on 27 Nov 2009, 04:02 PM
Hello Luis,

Here is how to get the text of an adjacent cell in the same row:
<telerik:GridTemplateColumn UniqueName="Test">
    <ItemTemplate>
        <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/img.png" AlternateText="Button"
            OnClick="ImageButton1_Click" />
    </ItemTemplate>
</telerik:GridTemplateColumn>

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
    GridDataItem item = (sender as ImageButton).NamingContainer as GridDataItem;
    RadAjaxPanel1.Alert(item["ColumnName"].Text);
}

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Luis
Top achievements
Rank 1
answered on 27 Nov 2009, 05:23 PM
If you aren't the best you're one of them


thanks a lot
Tags
Grid
Asked by
Luis
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Luis
Top achievements
Rank 1
Share this question
or