DataGrid SortCommand does not fire

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2009
Posts: 2
Reputation: Oskowich is an unknown quantity at this point 
Solved Threads: 0
Oskowich Oskowich is offline Offline
Newbie Poster

DataGrid SortCommand does not fire

 
0
  #1
Oct 21st, 2009
I have a DataGrid that I create dynamically in codebehind. I add events to the datagrid, it works fine except of the SortCommand event. It will not fire.
If I change my page_load to create and bind the datagrid everytime when a postback it works. But I don“t want to do an extra databind at a postback.
All other events is working fine so why not the SortCommand???
.net 1.1
Visual studio 2003

Thanx for any help and ideas!

  1. private void Page_Load(object sender, System.EventArgs e)
  2. {
  3. if(!IsPostBack)
  4. {
  5. createDataGrid();
  6. bindDataGrid();
  7. }
  8. else
  9. {
  10. createDataGrid();
  11. }
  12. }
  13.  
  14. private void createDataGrid()
  15. {
  16. //Set datagrid properties
  17. myDataGrid.ID = "myDataGrid";
  18. myDataGrid.AutoGenerateColumns = false;
  19. myDataGrid.AllowPaging = true;
  20. myDataGrid.PageSize = 20;
  21. myDataGrid.ShowHeader = true;
  22. myDataGrid.ShowFooter = true;
  23. myDataGrid.AllowSorting = true;
  24.  
  25. //Create datagrid events
  26. myDataGrid.ItemCommand += new DataGridCommandEventHandler(myDataGrid_ItemCommand);
  27. myDataGrid.PageIndexChanged += new DataGridPageChangedEventHandler(myDataGrid_PageIndexChanged);
  28. myDataGrid.ItemDataBound += new DataGridItemEventHandler(myDataGrid_ItemDataBound);
  29. myDataGrid.SortCommand +=new DataGridSortCommandEventHandler(myDataGrid_SortCommand);
  30.  
  31. //Create and add bound/template columns to myDataGrid
  32. ...
  33. }
  34.  
  35. private void bindDataGrid()
  36. {
  37. //Get data from databse and bind datagrid
  38. DataSet ds = new DataSet();
  39. ds = getDataFromDatabase();
  40. dgRuleTables.DataSource=ds.Tables[0];
  41. dgRuleTables.DataBind();
  42. }
  43.  
  44. private void myDataGrid_SortCommand(object source, DataGridSortCommandEventArgs e)
  45. {
  46. //Conde inside here will never be executed
  47. //SortExpression
  48. //Rebind datagrid with new sortexpression !
  49. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 225
Reputation: mail2saion is an unknown quantity at this point 
Solved Threads: 34
mail2saion's Avatar
mail2saion mail2saion is offline Offline
Posting Whiz in Training
 
0
  #2
Oct 22nd, 2009
Did your paging works without rebinding the data?
MARK AS SOLVED if its help you.

REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: Oskowich is an unknown quantity at this point 
Solved Threads: 0
Oskowich Oskowich is offline Offline
Newbie Poster
 
0
  #3
Oct 22nd, 2009
I found the solution. Instead of create datagrid with events in page_load I changed this to page_init.
More info:
http://forums.asp.net/t/947498.aspx
http://www.velocityreviews.com/forum...-solution.html
Reply With Quote Quick reply to this message  
Reply

Tags
.net, c#, datagrid

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for .net, c#, datagrid
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC