ASP.NET Add cell to Gridview row with string from code behind
I have a gridview display results from a LINQ query.
开发者_StackOverflow社区I want to add a column at the end that has a link. The issue is the link is dynamically generated in my code behind. I am not sure how to get this to the main page.
Thanks!
Check out the OnRowDataBound
event, you can use this event to create your link and insert it into the last cell. It will be fired each time a row is created and bound to a data item.
You can add a column to the GridView during PageLoad or some other event that fires once. You can then set the content of that column using it's RowDataBound function by using some thing a long these lines, where 0 is the index of the column:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Text = "*** results from your LINQ Query ****"
}
精彩评论