有条件地显示隐藏asp.net Gridview列(conditionally show hide asp.net Gridview column)

编程入门 行业动态 更新时间:2024-10-28 17:22:07
有条件地显示隐藏asp.net Gridview列(conditionally show hide asp.net Gridview column)

这是我如何导航到myPage.aspx ,

<a href='~/myPage.aspx?show=<%#Eval("id")%>' id="showEach" runat="server">Show Each</a> <a href="~/myPage.aspx?show=all" id="showAll" runat="server">Show All</a>

我在myPage.aspx有一个gridview

<asp:GridView ID="GridView1" runat="server"> <Columns> <asp:BoundField HeaderText="ColumnOne" Visible="true"/> <asp:BoundField HeaderText="ColumnTwo" Visible="true"/> </Columns> </asp:GridView>

我想要做的是,如果查询字符串等于all (〜/ myPage.aspx?show = all),我想将GridView1的Column2的可见性设置为true,否则将set可见为false。 我该怎么做 ?

This is how I navigate to myPage.aspx ,

<a href='~/myPage.aspx?show=<%#Eval("id")%>' id="showEach" runat="server">Show Each</a> <a href="~/myPage.aspx?show=all" id="showAll" runat="server">Show All</a>

And I have a gridview in myPage.aspx

<asp:GridView ID="GridView1" runat="server"> <Columns> <asp:BoundField HeaderText="ColumnOne" Visible="true"/> <asp:BoundField HeaderText="ColumnTwo" Visible="true"/> </Columns> </asp:GridView>

What I want to do is , if Query String is equal to all(~/myPage.aspx?show=all) , I want to set GridView1's Column2's visible to true , else , set visible to false . How can I do it ?

最满意答案

你可以使用gridview列索引来隐藏特定的列

代码可以

if(Request.QueryString.Get("show")=="all") GridView1.Columns[1].Visible=true; else GridView1.Columns[1].Visible=false;

更多详情

GridView按代码隐藏列

编辑1

我想是的

<asp:BoundField HeaderText="ColumnTwo" Visible='<% if (Request.QueryString.Get("all") == "all" ) "true" else "false" %>'/>

你将不得不检查syntex

编辑2

尝试这个

Visible='<% Request.QueryString.Get("all") == "all"? "true": "false"%>'

编辑3

不能直接完成。

<%=%>直接输出到响应流,并且asp标记不是响应流的一部分。 假设<%=%>运算符正在对asp标记执行任何类型的预处理是错误的。

更多解释

为什么将<%=%>表达式作为服务器控件上的属性值导致编译错误?

you can use gridview column index to hide the particular column

Code could be

if(Request.QueryString.Get("show")=="all") GridView1.Columns[1].Visible=true; else GridView1.Columns[1].Visible=false;

More detail

GridView Hide Column by code

Edit 1

I think yes

<asp:BoundField HeaderText="ColumnTwo" Visible='<% if (Request.QueryString.Get("all") == "all" ) "true" else "false" %>'/>

You will have to check for the syntex

Edit 2

Try this

Visible='<% Request.QueryString.Get("all") == "all"? "true": "false"%>'

Edit 3

Can not be done directly.

<%= %> outputs directly to the response stream, and the asp markup is not part of the response stream. Its a mistake to assume the <%= %> operators are performing any kind of preprocessing on the asp markup.

More explanation

Why will <%= %> expressions as property values on a server-controls lead to a compile errors?

更多推荐

本文发布于:2023-07-30 08:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336678.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有条件   net   asp   Gridview   column

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!