简体   繁体   中英

How to hide footer row in GridView in c#

I have a gridview that is bound on page load and I've implemented insert using the footer row technique.

However I want to have the footer row hidden for all users and only show for administrator users.

I used this line without success, because the footer row are showed for all users.

I'd greatly appreciate any suggestions.

Thanks!

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        ImageButton Download = (ImageButton)e.Row.FindControl("Download");
        Label File = (Label)e.Row.FindControl("File");
    }

    if (e.Row.RowType == DataControlRowType.Footer)
    {
        if (administratorUsers.ToString() == "1")
        {
            GridView1.ShowFooter = true;
            GridView1.FooterRow.Visible = true;
        }
        else
        {
            GridView1.ShowFooter = false;
            GridView1.FooterRow.Visible = false;
        }
    }
}

Please do this outside the RowDataBound event. You can try this in the Page Load or Page PreRender event:

GridView1.ShowFooter = administratorUsers.ToString() == "1";

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