Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 918543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:23:40+00:00 2026-05-15T18:23:40+00:00

I shall attempt to explain the scenario. I have a gridview I wish to

  • 0

I shall attempt to explain the scenario.

I have a gridview I wish to amend according to the preferences a user may set. These preferences being stored within a table in a EDMX (tblPref). The table gives the prefernce i.e. Product, the Alias for the preference i.e. SKU and whether the Preference should be shown i.e. ShowProduct?

So for example, the ‘standard grid’ would look like this:

Product  UUF1   UUF2
1        a        d
2        b        e
3        c        f

tblPreference would look like the following:

Preference Alias   ShowPreference
Product    Product     1
UUF1       UUF1        1
UUF2       UUF2        1

However, it may be the case that user may wish to see different columns i.e.

Product     UUF2
    1        d
    2        e
    3        f

tblPreference would look like the following:

Preference Alias   ShowPreference
Product    Product     1
UUF1       UUF1        0
UUF2       UUF2        1

And/Or they wish to label the headers with different text i.e.

   SKU    Category Sub-Category
    1        a        d
    2        b        e
    3        c        f

tblPreference would look like the following:

Preference Alias   ShowPreference
Product    SKU             1
UUF1       Category        1
UUF2       Sub-Category    1

Now then, I realise that it is possible to hide columns (gridview.columns[0].Visbile = False) and that I can amend header text (gridview.HeaderRow.Cells[0].Text = “Sku”).

What I am unsure is how I bring it altogether…the important part!

Obviously a fair few ‘ifs’ will be involved but I was wondering if anyone had done anything like this before and could provide a bit of pseudo code?

The reason I am going down this route is that I may have several hundred users who could potentially want the gridview to look completely different to them. Being a newbie, it is also good for me to try more difficult things rahter than ‘dragging and dropping’.

Therefore any help provided will be gratefully received.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:23:41+00:00Added an answer on May 15, 2026 at 6:23 pm

    If you have your grid set up like this in the aspx file.

    <asp:GridView runat=server ID=grid1 AutoGenerateColumns=false></asp:GridView>
    

    Then you should be able to use the code in the following to dynamically create the fields that are needed in the grid.

    using (SqlConnection conn = new SqlConnection("MySqlConnectionString"))
    {
        conn.Open();
        SqlCommand cmd = new SqlCommand("select * from tblPreference"); // you will also have to limit this selection to only rows for this user.
        cmd.Connection = conn;
        using (SqlDataReader dr = cmd.ExecuteReader())
        {
            while (dr.Read())
            {
                if(dr.GetInt32(dr.GetOrdinal("ShowPreference"))==1) //not sure if this is a bit or int field
                {
                    grid1.Columns.Add(new BoundField(){ 
                        HeaderText = dr.GetString(dr.GetOrdinal("Alias")),
                        DataField = dr.GetString(dr.GetOrdinal("Preference"))
                    });
                }
    
            }
        }
    }
    

    While I’m sure this will have to be adapted a bit for your specific use. It should give you a good start. Note that after running the above to set up your columns, you will still need to provide the grid with data either with a DataSource control or by manually binding it like below

    grid1.DataSource = MyDataReader; //or data table, or collection of objects
    grid1.DataBind();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I shall try to explain clearly what I need to be able to
I am implementing view controllers that shall have different behaviour. They have a common
I have a small issue logging in with a webservice being hosted using HTML
We have trouble with keeping apart our different configurations. Allow me to explain with
I have encrypted documents. After unarchiving each document, I need to prompt the user
Scenario I am attempting to implement supervised learning over a data set within a
In my continuing attempt to understand how pseudo-terminals work, I have written a small
When shall i use malloc instead of normal array definition in C? I can't
When shall I free my unsigned char* if I need to pass the unsigned
What technique shall one use to implement batch insert/update for Backbone.sync?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.