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

GridButtonColumn version of "OnClick"

3 Answers 516 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ahmad
Top achievements
Rank 1
Ahmad asked on 27 Dec 2011, 05:10 AM
Hi,

I just started using telerik few days ago
i would like to know what is telerik:GridButtonColumn attribute of Asp:button "OnClick"

what i want to do is let the user choose a meeting session in a grid list.
user will press the button and it will trigger OnClick funtion at the aspx.cs and also pass the ID of that meeting session /row.

using C#

hope you can help me in this.

thanks

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 27 Dec 2011, 05:33 AM
Hello Ahmad,

You can attach the "onclick" event by accessing the GridButtonColumn and pass the index.
C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
 {
      GridDataItem item = (GridDataItem)e.Item;
       LinkButton link = (LinkButton)item["UniqueName"].Controls[0];
       int index = e.Item.ItemIndex;
       link.Attributes.Add("onclick", "passindex('" +index  + "');");
  }
}
JS:
<script type="text/javascript">
 function passindex(index)
 {
   alert(index);
 }
</script>

Thanks,
Princy.
0
Ahmad
Top achievements
Rank 1
answered on 27 Dec 2011, 06:54 AM
Hi, thanks for the reply

i tried your code but the "GridDataItem" is underlined in red saying "The type or namespace name 'GridDataItem' could not be found (are you missing a using directive or an assembly reference?)"

i already added this:
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

is there anything more to add?
0
Accepted
Shinu
Top achievements
Rank 2
answered on 27 Dec 2011, 11:24 AM
Hello Ahmad,

Try adding the namespace "using Telerik.Web.UI;" in the CS page.

-Shinu.
Tags
Grid
Asked by
Ahmad
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ahmad
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or