如何动态显示和隐藏ASP.NET数据网格中的列 [英] How do I show and hide columns in ASP.NET datagrid dynamically
本文介绍了如何动态显示和隐藏ASP.NET数据网格中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的DataGrid是这样的:
My DataGrid is something like this:
<pre><asp:DataGrid ID="tasks" runat="server" AutoGenerateColumns="False" GridLines="None">
<HeaderStyle CssClass="task-list-header"/>
<ItemStyle CssClass="task-list-row"/>
<Columns>
<asp:BoundColumn DataField="Name"
HeaderStyle-Width="100px"
HeaderText="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="Description"
HeaderStyle-Width="250px"
HeaderText="Description"></asp:BoundColumn>
<asp:BoundColumn DataField="IsComplete"
HeaderStyle-Width="125px"
HeaderText="Is Complete"></asp:BoundColumn>
<asp:TemplateColumn>
<HeaderStyle Width="75px"/>
<ItemTemplate>
<asp:HyperLink ID="Hyperlink1" runat="server"
NavigateUrl='<%# ModuleContext.EditUrl("TaskId", Eval("TaskId").ToString(), "EditTask") %>'
Text="Edit"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderStyle Width="75px"/>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CommandArgument='<%# Eval("TaskId") %>' CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
这基本上是最后一个任务列表编辑和删除2列。我正在使用DNN8。如果用户未以超级用户身份登录,我想隐藏编辑和删除链接。我怎么能这样做?
我尝试过:
我使用OnAutoBinding属性尝试了该属性,并在后面的代码中定义了一个函数,但我没有再进一步了。感谢hwlp。
This is basically a list of Task with Last 2 columns as Edit and Delete. I am using DNN8. I want to hide the Edit and Delete links if the user is not logged in as Superuser. How can I do that?
What I have tried:
I tried the property using the OnAutoBinding attribute and defining a function in the code behind but I didn't go any further. Thanks for the hwlp.
推荐答案
bool isSuperUser = checkIsSuperUser();
if (!isSuperUser)
{
tasks.Columns[3].Visible = false; // edit column index
tasks.Columns[4].Visible = false; // delete column index
}
这篇关于如何动态显示和隐藏ASP.NET数据网格中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文