Hi, i have a grid with a GridButtonColumn. When the button is clicked i want to redirect the user (in javascript, and pass a long the bound value of the GridButtonColumn). i found how to do this serverside, but i cant figure out how to catch the click (and the value) in javascript.
Any help would be appriciated.
Any help would be appriciated.
4 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 25 Nov 2011, 11:05 AM
Hello Kirie,
Try the following code.
C#:
Thanks,
Princy.
Try the following code.
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["ColumnUniqueName"].Controls[0]; link.Attributes.Add("onclick", "functionName('" + item.ItemIndex + "');"); }}Thanks,
Princy.
0
Kirie
Top achievements
Rank 1
answered on 28 Nov 2011, 08:48 AM
Thank you for your swift answer Princy,
but what if i want to send the bound DataTextField as a parameter to the javascript method, (or one of the other columns bound value), how can I acheieve that? I am kind of new to javascript :)
Best regards
Kirie
but what if i want to send the bound DataTextField as a parameter to the javascript method, (or one of the other columns bound value), how can I acheieve that? I am kind of new to javascript :)
Best regards
Kirie
0
Shinu
Top achievements
Rank 2
answered on 28 Nov 2011, 10:01 AM
Hello Kirie,
Try the following javascript:
JS:
-Shinu.
Try the following javascript:
JS:
function functionName(index){ var row = $find('<%= RadGrid1.ClientID %>').get_masterTableView().get_dataItems()[index]; alert(row.getDataKeyValue("ID"));}-Shinu.
0
sina
Top achievements
Rank 1
answered on 29 Aug 2017, 11:15 AM
hello there,
thanks for your answers.
I get this cast error:Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.LinkButton
it belongs to this line : LinkButton LinkButton1 = (LinkButton ) ditem["TemplateColumn3"].Controls[0]
please tell me how can i cast that.