Add Button to GridView's Cell from code behind

kentuckysob

New Member
I use below code for add Button to GridView's Cell from code behind,but when i click on each button that i add,the click event(lnk_Click) doesn't call and button hides after i click on it.how can i solve this problem?\[code\]//aspx<asp:GridView ID="GridView1" runat="server" GridLines="None" Width="940px" OnSelectedIndexChanged="grid_SelectedIndexChanged" onrowdatabound="GridView1_RowDataBound" AutoGenerateColumns="False" CssClass="gridview"> <Columns> <asp:TemplateField HeaderText="..."> <ItemTemplate> <asp:Panel ID="pnlSteps" runat="server"></asp:Panel> </ItemTemplate> </asp:TemplateField> </Columns>\[/code\]\[code\]//Code behindfor (int i = 0; i < GridView1.Rows.Count; i++) { Panel pnl = (Panel)GridView1.Rows.Cells[0].FindControl("pnlSteps"); LinkButton lnk = new LinkButton(); lnk.Text = "..."; pnl.Controls.Add(lnk); lnk.Click += new EventHandler(lnk_Click); }//for...protected void lnk_Click(object sender, EventArgs e) {//...}\[/code\]
 
Back
Top