I have a GridView which contains a linkbutton in its templatefield. What I want to know is, when I click on the linkbutton, how can I get the text of the linkbutton into a string called 'name'?
+3
A:
Provide event handler for Click event:
<asp:GridView id="myGrid" runat="server">
<columns>
<asp:templatefield>
<itemtemplate>
<asp:LinkButton id="MyButton"
Text="SuperText"
OnClick="MyButton_Click"
runat="server"/>
</itemtemplate>
</asp:templatefield>
</columns>
</asp:GridView>
In event handler use the following code:
protected void MyButton_Click(object sender, EventArgs e)
{
LinkButton btn = sender as LinkButton;
if(btn != null)
string name = btn.Text; // SuperText
}
Pavel Morshenyuk
2010-08-18 08:38:24
Thank you very much Pavel. This is what I am looking for. :)
pRAVeEN
2010-08-20 05:28:48
Please mark answer as correct if it is what you looking for - so other people will be able to see it. :)
Pavel Morshenyuk
2010-08-20 06:14:46