I'm a newbie to asp.net. I created one dynamic gridview. In that I created two templatefields. I want to add two link buttons in the last two cells of each row. Here is my code:
void grdv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lnkupdate= new LinkButton();
lnkupdate.ID = "Update";
lnkupdate.Text = "Update";
LinkButton lnkdelete = new LinkButton();
lnkdelete.ID = "delete";
lnkdelete.Text = "delete";
e.Row.Cells[2].Controls.Add(lnkupdate);
e.Row.Cells[3].Controls.Add(lnkdelete);
}
}
Andrei provided the answer in the comments, I'm just moving it out into a proper answer.
It was determined that nixen09 needs to access the last 2 cells in the row, this is one way to do that.
e.Row.Cells[e.Row.Cells.Count - 2]
and e.Row.Cells[e.Row.Cells.Count - 1]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.