views:

51

answers:

2

I am struggling to show different views of gridview with database values. Here is my requirement.

Database Table: alt text

I need to show one drop downlist with three values 1,2,3. If user selects 3 i Need to show a grid like below

alt text

Age,AnnualSales and Assortment are names which are coming dynamically from database.

High,Medium and Core all are values

Here my question is I need to show same attribute names.

Like If the name changes from "Assortment" to "Location" I need to show it in different page index .

In page index 2 i need to show like below.

alt text

Please help with solution

A: 

One solution could be, generating columns in codebehind. e.g.

BoundField bf = new BoundField();
bf.HeaderText = "HeaderText";
bf.SortExpression = "Datafield";
bf.DataField = "Datafield";
GridView1.Columns.Add(bf);

One could write own TemplateClasses if required. There are lot of examples over net. one would be

http://www.codeproject.com/KB/aspnet/create_template_columns.aspx

Tweak column headers or columns of gridview as required.

hope this helps you.

Saar
A: 

You can do this very well by setting the property dynamically.

GridView1.Columns[2].HeaderText = "Location";

I have worked pretty well using GridViews and databound controls in most dynamic ways. If you need help from me, please visit my website for further contact - ConsultSarath.com