fred williams
Top achievements
Rank 1
fred williams
asked on 22 Jul 2010, 03:56 PM
I have a template column in my grid with linkbuttons. I'd like to be able to retrieve the datakey value of the row by clicking this button. How would I go about doing this?
4 Answers, 1 is accepted
0
Cori
Top achievements
Rank 2
answered on 22 Jul 2010, 05:15 PM
The simple approach would be to bind the CommandArgument property of your LinkButton to the data key you need, which would accessible through the Bind expression since it's a column in the data source and then handle the LinkButton's OnCommand event.
I hope that helps.
I hope that helps.
0
fred williams
Top achievements
Rank 1
answered on 22 Jul 2010, 05:55 PM
Hello and thanks for the reply. Do I simply add the name of the key field in the CommandArgument property? The Key field is called ID in the database.
Here's the code I have so far:
When I test it all lblShow.Text displays is the word "ID".
Here's the code I have so far:
<telerik:GridButtonColumn ButtonType="LinkButton" CommandName="Select" CommandArgument="ID" Text="View Map" UniqueName="Select"/>
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
If e.CommandArgument = "ID" Then
Dim ID As String = e.CommandArgument.ToString()
lblShow.Text = ID
End If
End Sub
When I test it all lblShow.Text displays is the word "ID".
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Jul 2010, 07:40 AM
Hello Fred,
Instead of GridButtonColumn you can use GridTemplateColumn with LinkButton in ItemTemplate and try the following code snippet.
ASPX:
VB.Net:
Thanks,
Princy.
Instead of GridButtonColumn you can use GridTemplateColumn with LinkButton in ItemTemplate and try the following code snippet.
ASPX:
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:LinkButton
ID
=
"LinkButton1"
runat
=
"server"
CommandName
=
"Select"
CommandArgument='<%# DataBinder.Eval(Container.DataItem,"ID") %>'
Text="View Map"></
asp:LinkButton
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
VB.Net:
Protected
Sub
RadGrid1_ItemCommand(source
As
Object
, e
As
GridCommandEventArgs)
If
e.CommandName =
"Select"
Then
Dim
ID
As
String
= e.CommandArgument.ToString()
lblShow.Text = ID
End
If
End
Sub
Thanks,
Princy.
0
fred williams
Top achievements
Rank 1
answered on 23 Jul 2010, 02:45 PM
Worked perfectly, thanks!