[英]How do I make several gridview columns invisible dynamically?
我在用
e.Row.Cells[0].Visible = false;
使單個列不可見。 它工作,但當我嘗試添加另一個像這樣:
e.Row.Cells[0].Visible = false;
e.Row.Cells[1].Visible = false; //i tried listing all and still got the out of range error
我得到錯誤Specified argument was out of the range of valid values. Parameter name: index
Specified argument was out of the range of valid values. Parameter name: index
我正在使用Gridview的RowDataBound
事件中的命令,從0開始,gridview有12列
考慮到GridView
有一些不是數據的行(尋呼機,頁腳等)。
我說你應該有這樣的事情,所以你只能躲在邏輯應用到DataRow
元素。
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Visible = false;
e.Row.Cells[1].Visible = false;
}
要查看所有行類型,請查看此MSDN文章 。
如果Gridview的RowCreated
= true,則可能需要將代碼放入RowCreated
事件而不是RowDataBound
事件。
以下是類似的答案: 如何使用自動生成的列隱藏列
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.