locked
How to display certain columns to certain user in dynamic data site RRS feed

  • Question

  • User1160430963 posted

    Hi

    I have created an Dynamic data site with ASP.NET, c# and EF(Database first Approach) in which i want to display selected columns to certain users (i.e., Role Based)

    in gridview.

    for ex:  the table has 20 columns but i like to display only selected 5 columns of those 20 in the gridview for a selected user, how can i accomplish this, kindly help.

    Also kindly help me in creating users for dynamic data site, c# using ADO.net (Database first Approach).

    Thanks in Advance

    Wednesday, November 20, 2013 4:10 AM

Answers

  • User852518098 posted

    Hi,

    Based on condition, you can hide the gridview columns at run-time. Write the required condition in DataBound event.

    The following code will useful,

    protected void GridView1_DataBound(object sender, EventArgs e)
        {
            if (Role == "Guest")
            {
                GridView1.Columns[2].Visible = false;
                GridView1.Columns[3].Visible = false;
    
            }
            else
            {
                GridView1.Columns[2].Visible = true;
                GridView1.Columns[3].Visible = true;
    
            }
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 20, 2013 5:42 AM

All replies

  • User852518098 posted

    Hi,

    Based on condition, you can hide the gridview columns at run-time. Write the required condition in DataBound event.

    The following code will useful,

    protected void GridView1_DataBound(object sender, EventArgs e)
        {
            if (Role == "Guest")
            {
                GridView1.Columns[2].Visible = false;
                GridView1.Columns[3].Visible = false;
    
            }
            else
            {
                GridView1.Columns[2].Visible = true;
                GridView1.Columns[3].Visible = true;
    
            }
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 20, 2013 5:42 AM
  • User-330204900 posted

    Hi naikotiarun, have a look at my article here A New Way To Do Column Generation in Dynamic Data ...

    Friday, December 27, 2013 10:20 AM