我需要在事件rowdatabound中的gridview中找到总列数。是否有任何方法。 以下是我的几个代码:
protected void gvEmployee_RowDataBound(object sender, GridViewRowEventArgs e)
{
LinkButton lnkView = new LinkButton();
lnkView.ID = "lnkView";
lnkView.Text = "View";
lnkView.Click += ViewDetails;
e.Row.Cells[3].Controls.Add(lnkView);
}
答案 0 :(得分:3)
您可以将发件人转发给GridView
并获取计数。
protected void gvEmployee_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(!(sender is GridView))
return;
GridView gridView = (GridView) sender;
var colCount = gridView.Columns.Count;
//Your code
}
答案 1 :(得分:2)
不确定为什么要这样,但Cells
是此行中单元格的数组,因此要获取列总数:
protected void gvEmployee_RowDataBound(object sender, GridViewRowEventArgs e)
{
var colCount = e.Row.Cells.Count;
}