I have a GridView .In this GridView we are dynamically generating columns . We have also set Autogenerate columns to true in the GridView. Now the issue I am dynamically adding linkbutton to that columns .
ISSUE : Link button click is not working .It is doing a postback and all the links are disappeared.I have tried adding commands and click event but none of them are working. Any help would be appreciated.
Code Behind :
protected void GridViewTest_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.DataItem != null && e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
LinkButton link = new LinkButton();
link.Text = e.Row.Cells[i].Text;
link.EnableViewState = true;
link.Click += new EventHandler(onLinkClick);
e.Row.Cells[i].Controls.Add(link);
}
}
}
protected void onLinkClick(object sender, EventArgs e)
{
this.ModalPopupExtender1.Show();
}
ASPX :
<asp:GridView
ID="GridViewTest"
runat="server"
AutoGenerateColumns="true"
CssClass="resultsTable"
Width="100%"
CellPadding="2"
CellSpacing="0"
GridLines="None"
autogenerateeditbutton="true"
OnRowDataBound="GridViewPullHistory_RowDataBound"
OnRowCreated="GridViewPullHistory_RowCreated">
<AlternatingRowStyle CssClass="gridRow1" HorizontalAlign="Center" />
<RowStyle CssClass="gridAltRow1" HorizontalAlign="Center" />
<HeaderStyle CssClass="gridHeader" Font-Bold="true" HorizontalAlign="Right" />
</asp:GridView>