ASP.Net Grid Control Link Button

  • Thread starter Thread starter Robin
  • Start date Start date
R

Robin

In an ASP.NET page that has a data grid with a bound column of link button.
How can I reference the control and set properties for the link button at
run time?
 
Hi Robin,

This is so simple!

foreach (DataGridItem item in dgCustomers.Items)
{
TableCell cell = item.Cells[0];
LinkButton button = (LinkButton) cell.Controls[0];
button.Text = "some text";
}


The above example assumes that your DataGrid is named dgCustomers and the LinkColumn is the first column in DataGrid. That's why I have written Items.Cells[0]. You can reference any columns using its index through Items.Cells.

The LinkButton has also other properties like NavigateUrl that you can set at run time.

Hope this helps! Please feel free to ask any questions if you are still confused with this.

Best Wishes,
Mosh
 
Back
Top