DataGrid Sort ok but not reflected in DataGrid

operaminix

New Member
Sort works fine (checked with response.write ...). But new DataBind does NOT show sort in Datagrid. See below code!<BR>- what do I do wrong?!<BR>Thanks ed<BR><BR>Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles DataGrid1.SortCommand<BR> SqlDataAdapter1.Fill(DataSet11, "Club")<BR> Dim myDataView As DataView = DataSet11.Tables ("Club").DefaultView<BR><BR> ' sort<BR> myDataView.Sort = e.SortExpression<BR><BR> ' check outcome of sort<BR> Response.Write(e.SortExpression)<BR> Response.Write(myDataView.Count)<BR> Response.Write("sorted as: ")<BR> Dim I As Integer<BR> Dim rowCount As Integer = myDataView.Count<BR> For I = 0 To rowCount - 1<BR> 'Response.Write(" T:")<BR> 'Response.Write(myDataView.Table.Rows(I).Item( 0))<BR> Response.Write("* ")<BR> Response.Write(myDataView.Item(I)(e.SortExpression ))<BR> Next<BR><BR> DataGrid1.DataSource = myDataView<BR> DataGrid1.DataBind()<BR> End SubI'm working with ASP.Net and DataGrids and use a line as follows:<BR><BR>objDataView.Sort += e.SortExpression & " ASC"<BR><BR>I then bind to the dataview as you did.<BR><BR>Hope it helps.<BR><BR>TTthanks for looking into it.<BR><BR>unfortunately it still does not give me back the sorted view in the Grid. As said with the response.write(... statements I see that the view is sorted ok! eg I can use below statement and get it descending - but no change in the re-binded Grid!<BR><BR>question: in your statement I tried to use the + sign - it works with or without it (what is the reason you use the + sign!?<BR><BR>myDataView.Sort = e.SortExpression & " DESC"<BR>DataGrid1.DataSource = myDataView<BR>DataGrid1.DataBind()<BR><BR>thanks edThat's odd.........<BR>I assume that you have <BR>AllowSorting = "True" <BR>OnSortCommand = "your sort sub's name"<BR>on your datagrid's properties?<BR><BR>TT... well I don't understand it either!<BR><BR>-the Grid definitions show "AllowSorting=True"<BR>as said the sort is in fact ok - I can test it with the response.write statements as seen in my first msg which also shows complete SUB: "DataGrid1_SortCommand"<BR>PS: I dragged the DataGrid onto the WEBform and use only the 'Property Builder' to set the properties. <BR>I defined sorting in the DataGrid for all columns and I can sort on all columns ok (ASC and DESC).<BR><BR>It must have something to do with the 'Bind'. Somehow it seems that it does not recognise 'myDataView' as a new source! (statement: DataGrid1.DataSource = myDataView)<BR><BR>any idea how I can/should proceed!?<BR>THANKS ed <BR><BR>OK, Now I'm bothered.<BR><BR>I did some checking pulling in a dataset from a database. The database is indexed on the date field. I add a new record to the datatable in the dataset, do the source update then sort the database table using;<BR><BR>objDataSet.Tables("Scores").Select(Nothing,"Date DESC")<BR><BR>I then bind the dataset to my datagrid and the latest entry (which is the latest date) is still shown last in the datagrid.<BR><BR>I can click on the date column in the datagrid to sort and it sorts normally.<BR><BR>This is similar to a problem that existed in VB6 when working with recordsets and doing inserts. From what I've read, it's some kind of timing issue.<BR><BR>Does your datagrid sort if you click the column ?<BR><BR>TTTom, I really appreciate the time you spend ...<BR><BR>Does the datagrid sort? well yes in the background BUT it does NOT show in the DataGrid on the screen ie the grid never changes!<BR><BR>It definitely sorts the DataView ie when I read it it is correctly sorted and, in fact, I use it to proceed in my application (all is correct), however it's annoying that I cannot show it on the screen!<BR>Contrary to you- I do Not add any rows or do NOT modify it in any way - I just sort it.<BR><BR>Again, I am now looking into the Bind business - it seems that the ....datasource = myDataView is not recognised. Do I miss anything there - if you would check my code again as provided in my 1st msg - might be I do something stupid there!?<BR><BR>thanks ed <BR>just did a test with below code. <BR>Conclusion: when defining below 'myDataView' pulling only selected rows (TX; and I can see only the selected rows when using 'WriteView(myDataView)') -- at Bind, however, I still get full DataSet in Grid.<BR>Conclusion: it has nothing to do with the Sort; it seems a matter of binding 'myDataView' as a new source!<BR>any Idea?!<BR><BR>Private Sub CustomDV_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CustomDV.Click<BR> ' Select all 'State=TX', sorted by 'City, Address', get 'CurrentRows' <BR> SqlDataAdapter1.Fill(DataSet11, "Club")<BR> Dim myDataView As DataView = New DataView(DataSet11.Tables("Club"), "State='TX'", "City, Address", DataViewRowState.CurrentRows)<BR> Response.Write("in CustomDV" + ControlChars.CrLf)<BR><BR> 'Write all fields as single instancies to rebuild the rows<BR> WriteView(myDataView)<BR> DataGrid1.DataSource = myDataView<BR> DataGrid1.DataBind()<BR> End Subaddl tests show that issue has nothing to do with sort BUT with changing the Grid.DataSource with new DataView info<BR><BR>I opened a new thread "Changing DataGrid.DataSource fails" <BR><BR>Tom thanks for all your help, edI'm not sure I understand the source of the problem, but I'm glad to hear you worked it out.<BR><BR>Tom T
 
Back
Top