Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have Datalist which display link buttons with text fetch from database .
what i want is , when i click on any link button , i want to get the text of that link button which i clicked.

Do provide a example if possible
Posted
Updated 9-Jan-14 23:29pm
v2

Hi,

In click event of your link button you have first argument as object(Sender). You need to type cast that object into LinkButton and then you can get text of that button.

That will work for you
Thanks
Amit
 
Share this answer
 
v2
You can subscribe to DataList_ItemCommand event.
C#
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
    LinkButton lb = source as LinkButton;
    if(lb != null) 
    {
        string clickedText = lb.Text;
    }
}
 
Share this answer
 
C#
string sd;
 sd = ((LinkButton)sender).Text;

 Response.Redirect("Page.aspx?id=" + sd);


I get the text of selected link button.
Solved
 
Share this answer
 
v2
try this
C#
protected void Data_Walking_List_ItemCommand(object source, DataListCommandEventArgs e)
  {

          LinkButton mylink = (LinkButton)e.Item.FindControl("Link_ViewDetials");
          //Label city = (Label)e.Item.FindControl("City");
          //Response.Cookies["city"].Value = city.Text;






  }
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900