gpt4 book ai didi

c# - 使用 rowdatabound 计算列数

转载 作者:太空宇宙 更新时间:2023-11-03 20:05:40 25 4
gpt4 key购买 nike

我需要在事件 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);
}

最佳答案

您可以将 sender 转换到 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
}

关于c# - 使用 rowdatabound 计算列数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23631028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com