Hi,
I need to add the columns dynamically inside the Group Field . so that one or more columns will be created dynamically in the Group Header.
Hello,
I'm just following up to see if you managed to resolve your issue using the suggested. If you need any further assistance, please let me know.
Hello Kumar,
I see what you want to do. Since you do not know how many subjects will come from the data source I assume you are using AutoGenerateColumns=true for your WebDataGrid.
Then the grid will render a column for each field from the database and you want those fields that are in fact subjects to be grouped under a multi header. Following this scenario I prepared a sample for you that demonstrates how this could be achieved:
***
The WebDataGrid1_Load server event is handled where:
1) Multi-Column Header is defined programmatically:
GroupField MultiColumnHeaderSubjects = new GroupField();MultiColumnHeaderSubjects.Key = "Subject";MultiColumnHeaderSubjects.Header.Text = "Subject";
2) Then a simple check is executed to determine which column is a subject nd then those columns are added to the MultiHeder (I used hardcoded values but it will be better if you could set some flag on your datasource fields and check for this flag here)
if (key == "Maths" || key == "English" || key == "Physics") { MultiColumnHeaderSubjects.Columns.Add(WebDataGrid1.Rows[0].Items[t].Column); }
3) The MultiHeader is added to the WebDataGrid columns' collection:
this.WebDataGrid1.Columns.Add(MultiColumnHeaderSubjects);
Please be aware that using AutoGenerateColumns=true and adding columns programmatically will result in the columns be rendered twice. This is why the WebDataGrid1_Grid_Initialize client side event is handled where the redundant columns are hidden with set_hidden(true).
Please review it and let me know if it meets your requirements.
Hi Guys.
I need to create the rows dynamically using WebDataGrid in the aspx.cs File. Help Me
For Example :
In the Below table The Subject Names are come from the datatable , there may be more than 7 subject thats what i need to Create the
Webdatagrid in this Format..
If there is Solution Kindly let me know.
Name
Regards,
Manoj Kumar.R
Please refer to the following resources:
Add/Remove columns from WebDataGrid
Configuring WebDataGrid Multi-Column Headers
They demonstrate how you can add/remove columns and add columns inside GroupField's collection programartically. I hope it helps.