Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
ASP .Net
ASP .Net Datagrid Control
DataGrid Sort Problem
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Courtney, post: 4259085"] Everyone, I am having problems with sorting in a c# webform datagrid. The problem manifests itself in the heading text. When I turn on sorting, the column headings dissappear. After selecting on a row in the grid, they reapear. If I select on one of the headings to sort, the grid sorts and the headings dissapear. If I select a row again, the heading text reappears. A little background on the application I am building. Just about everything is built on the fly. I have a search page fills an Xml document with data then redirects to the results page (with the datagrid). Onload, the grid 1. creates a dataview from some of the data in the xmldocument. 2. Builds column for the datagrid based on the columns in the dataview. 3. binds the dataview to the datagrid. There are some other details going on but that is the general flow. The selected index change does not do much. When I sort, I am rebuilding the whole datagrid again. The problem obviously comes with how I am buiding the grid but I do not understand how or why. Any advice would be greatly appreciated. Also, if there is a better way to do what I am doing, I would like to hear that as well. All relevant code is below. If you want to see the sourced, let me know. Thanks. Courtney PageLoad code: //Build the columns based on the nodelist this.BuildDynamicColumns(currentDataView); //Load the DataGrid //This binds the dataview to the DataGrid LoadDataGrid(currentDataView); Build Columns function: private void BuildDynamicColumns(DataView myDV) { //Setup the DataGrid ResultsDG.AutoGenerateColumns = false; //Paging Properties ResultsDG.AllowPaging = true; //Sorting Properties ResultsDG.AllowSorting = true; //Remove Columns if they already exist if (ResultsDG.Columns.Count > 1) { for (int i=1; i < ResultsDG.Columns.Count; i++) { ResultsDG.Columns.Remove(ResultsDG.Columns[i]); i--; } } //Check to see if there are any columns in the DataView if (myDV.Table.Columns.Count != 0) { //Loop through the columns foreach (DataColumn myDVCol in myDV.Table.Columns) { string columnName = myDVCol.ColumnName; columnName = myCommon.InsertSpacesForCaps(columnName); BoundColumn myCol = new BoundColumn(); myCol.DataField = columnName; myCol.SortExpression = columnName; myCol.HeaderText = columnName; myCol.ItemStyle.Wrap = false; ResultsDG.Columns.Add(myCol); } } //Set the added property to true this.DynamicColumnsAdded = true; } LoadDataGrid function:[/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
ASP .Net
ASP .Net Datagrid Control
DataGrid Sort Problem
Top