I am generating gridview dynamically. Here is the code
Design Code
<asp:GridView Width="100%" CssClass="TTable" ID="MainGridView" OnDataBound = "OnDataBound" runat="server" AutoGenerateColumns="False" onrowdatabound="GridView_RowDataBound">
<Columns>
</Columns>
</asp:GridView>
Code Behind :
private void createGridView(DataTable gridviewdt)
{
MainGridView.Columns.Clear();
//Iterate through the columns of the datatable to set the data bound field dynamically.
foreach (DataColumn col in gridviewdt.Columns)
{
//Declare the bound field and allocate memory for the bound field.
BoundField bfield = new BoundField();
//Initalize the DataField value.
bfield.DataField = col.ColumnName;
//Initialize the HeaderText field value.
bfield.HeaderText = col.ColumnName;
//Add the newly created bound field to the GridView.
MainGridView.Columns.Add(bfield);
}
}
// Bind Datatable to gridview
MainGridView.DataSource = gridviewdt;
MainGridView.DataBind();
In the above code, I would like to put hyperlink on particular columns data. If I put the hyperlink directly on the Datatable, then it shows it as it is without executing.
<asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
How can I add above link button on some gridview columns ?