简体   繁体   中英

Showing/Hiding Grid On Page

For one user I need to show a different gridview so my thought is to create 2 grids and hide them both, and on Page_Load() show the appropriate gridview based off the userid. This works, but it is quite repetitive since the 2 grids are very similar. Is their a better way to achieve this or a more syntactically appropriate way?

Further Info - the for everyone grid has 16 fields
The YouOnly grid shares the same 16 but 4 additional fields is the only difference

HTML (just sampling of data)

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div id="TextTopOfPage" runat="server">This is the top of the page</div>
        <br />
        <div id="Alldiv" runat="server">
            <asp:GridView ID="ForAll" runat="server" visible="false"/>
        </div>
        <div id="YouOnlyDiv" runat="server">
            <asp:GridView ID="YouOnly" runat="server" Visible="false" />
        </div>
    </form>
</body>
</html>



C#

protected void Page_Load(object sender, EventArgs e)
{
    if (userid == "eac11") { this.YouOnly.Visible = true; }
    if (userid != "eac11") { this.ForAll.Visible = true; }
}

You need to bind the column definitions for all twenty columns in the ASPX. For the four special columns, change the visibility of the column based on the YouOnly property. You could likewise do it in the code behind using the OnDataBinding event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM