如何根据收到的Session隐藏GridView中的列 [英] How to hide a column in GridView according to recieved Session

查看:82
本文介绍了如何根据收到的Session隐藏GridView中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用BoundField属性填充了网格视图,之后我可以使用CSS类隐藏列,如下面的代码:

I have populated the grid view with BoundField property and after that I can hide a column with CSS class like following code:

<asp:BoundField DataField ="FieldNamde" HeaderText="FieldName" HeaderStyle-CssClass="hidden" ItemStyle-CssClass="hidden">





隐藏的CSS类设置如下



The CSS Class hidden is set as following

.hidden
{
display:none;
}



同样填充相同的网格视图我想要根据会话状态隐藏另一列,例如:


Also to populate the same grid view I want to hide another column according to session state for example:

if ((Session["SessionName"] != null ? (string)Session["SessionName"] : "") == "SomeText")





更确切地说,我想展示或根据Session隐藏列,如果SessionName是SomeText显示列,如果SessionName是OtherText我想隐藏列。

提前感谢您的回复。

干杯。



To be more precisely, I want to show or hide a column according to the Session and if SessionName is SomeText to show a column, if SessionName is OtherText I want to hide a column.
Thank you in advance for your reply.
Cheers.

推荐答案

我找到了一个解决方案,如果其他人遇到同样的问题,只需转到网格视图并选择事件RowCreated,然后写入代码如下:

I found a solution and in case that someone else has the same problem just go to grid view and select the event RowCreated and after that write the code as following:
protected void gvGridView_RowCreated(object sender, GridViewRowEventArgs e)
       {
             /// Session name
           if ((Session["SessionName"] != null ? (string)Session["SessionName"] : "") == "SomeText")
           {
                  /// Column that has DataField
                   if (e.Row.RowType == DataControlRowType.DataRow)
                   {
                       e.Row.Cells[0].CssClass = "hidden";
                   }
                   /// Column header
                   else if (e.Row.RowType == DataControlRowType.Header)
                   {
                       e.Row.Cells[0].CssClass = "hidden";
                   }
           }
       }





谢谢大家。



Thank you all.


这篇关于如何根据收到的Session隐藏GridView中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆