473,385 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Sorting DataGrid using Table.Select() DataRow Array

2
I have a hand built dataset where some columns come from a sql database and others are calculated and eventually I will have two different query results going into one table because its impossible for me to get all the data w/one query.

The problem I need help with is getting the DataGrid to reflect changes from a sort.

The foundRows DataRow array contains correctly sorted rows (verified), but I can't get the table updated in the DataGrid. I think my problem has to do with ViewState but I'm not sure. How would I update DataGrid from the sort results?

Expand|Select|Wrap|Line Numbers
  1.  
  2.     void dgridResults_SortCommand(object source, DataGridSortCommandEventArgs e)
  3.     {
  4.         collectionId = int.Parse(HttpUtility.UrlDecode(Request.QueryString["collectionId"]));
  5.         dsBuilder.GetResultsDataSet(dsResults, collectionId);
  6.         DataRow[] foundRows = dsResults.Tables["ResultTable"].Select("JobId > 0", "JobId ASC");
  7.  
  8.         for (int index = 0; index < foundRows.Length; index++)
  9.         {
  10.             dsResults.Tables[RESULT_TABLE].Rows[index].BeginEdit();
  11.             dsResults.Tables[RESULT_TABLE].Rows[index].ItemArray = foundRows[index].ItemArray;
  12.             dsResults.Tables[RESULT_TABLE].Rows[index].EndEdit();
  13.             dsResults.Tables[RESULT_TABLE].Rows[index].AcceptChanges();
  14.         }
  15.  
  16.         dgridResults.DataSource = dsResults;
  17.         dgridResults.DataBind();
  18.  
  19.     }
  20.  
  21.  
Oct 31 '08 #1
3 5522
DrBunchman
979 Expert 512MB
Hi joelzn,

Welcome to Bytes.com! I hope you find the site useful.

You've posted your question in the ASP Forum which is for Classic ASP only - I've moved it for you but in future please post all ASP.NET questions in the .NET Forum.

Thanks,

Dr B
Oct 31 '08 #2
joelzn
2
I was going about it the wrong way, here is the solution:

I removed the for loop and did this:

Expand|Select|Wrap|Line Numbers
  1.         DataView dv = dsResults.Tables[RESULT_TABLE].DefaultView;
  2.         dv.Sort = "JobId ASC";
  3.         dgridResults.DataSource = dv;
  4.         dgridResults.DataBind();
  5.  
Oct 31 '08 #3
DrBunchman
979 Expert 512MB
Glad you got it sorted, thanks for posting the solution.

Dr B
Oct 31 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: rodchar | last post by:
Hey all, I have an array of data rows that when I bind it to a datagrid it shows all those extra rows in addition to my fields. How do I hide those fields? I tried using the TableStyles...
1
by: xrow | last post by:
Hello I have a simple webservice / c# application that receives data from server and prints the data in the asp:datagrid control I have problem when sorting data in datagrid I have created...
1
by: steven shingler | last post by:
Hi all, I've got a datagrid. I have a function which selects certain rows in a datagrid thus: public void selectRows(string key, string columnName) { int count = 0; foreach(DataRow dr in...
1
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current...
5
by: Genojoe | last post by:
I am using code from Help with two exceptions. (1) I increased the number of sample rows from 3 to 20, and (2) I anchored the datagrid to bottom of form so that I can change the size of the grid by...
5
by: DKC | last post by:
Hi, Using VB.NET. I have a datagrid having a strongly typed array of objects as its data source. The data from the array of objects is displayed by means of a table style, which is fine, but...
3
by: WB | last post by:
Hi, I have a DataTable, which I'd like to sort before using it for other operation. However, I notice that even after I call the .DefaultView.Sort = "username", the view is still not sorted. For...
2
by: Flack | last post by:
Hey guys, I have a DataGrid and DataTable field in my class : private ImageDataGrid dataGrid1; //ImageDataGrid extends dataGrid and just overides OnMouseDown private DataTable dt = new...
2
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.