ASP.Net Grid Control Link Button

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?
 
M

Moshfegh Hamedani

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,057
Members
48,769
Latest member
Clifft

Latest Threads

Top