Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
In Gridview run mode as follows

SelectedBatchdate
27 May 2015
30 May 2015
5 June 2015
Click Here (Link button)

i written the code in gridview_databound as follows

protected void gvPkgcbndate_DataBound(object sender, EventArgs e)
{
LinkButton lnk = new LinkButton();
lnk.ID = "lnk";
lnk.Text = "click here";
lnk.Click += new System.EventHandler(lnk_Click);
}

protected void lnk_Click(object sender, EventArgs e)
{
Response.Write("you are selected the link button");
}

When user click the click here link button, the message not shown "you are selectedt eh link button";

Link button selected event is not firing.


please help me. what is the mistake i made in my above code.
Posted
Comments
F-ES Sitecore 27-Jul-15 4:12am    
You need to create the link\attach the events on every postback, so if your gridview isn't re-binding on postback (ie you have something like "if (!Page.IsPostback){BindData();}") then the event will not be active when the postback is triggered, you'll need to re-bind your gridview each postback.

1 solution

Hi Try to add
ASP.NET
runat="server"
properties in dynamically created link button.
or try this

C#
LinkButton lnk = new LinkButton();
lnk.ID = "lnk";
lnk.Text = "click here";
lnk.Click += new EventHandler(lnk_Click);



or try this

C#
LinkButton lb = new LinkButton();
lb.ID = "LinkButton1";
lb.Click += test;
lb.Text = "testtext";

protected void test(object sender, EventArgs e)
{
}

Regards
Aravind
 
Share this answer
 
v4

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