Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: datagrid


Message #1 by "Amit Kalani" <kalani@w...> on Fri, 13 Oct 2000 12:01:56 -0400
Hi:



I was trying something like this:



<asp: DataGrid id="DataGrid1"

runat="server"

PageSize="20"

Allowpaging="True"

AllowSorting="True"

/>



I bound this with pubs database and executed a query "select * from

authors". My table was having 23 records.



Initially 23 records were displayed, but when I clicked on ">" at the bottom

of the table, it didn't bring remaining records. Also there is nothing

working by clicking over the fields hyperlink (It would have sorted data on

that field)



Any thoughts?



TIA



Amit



Message #2 by "Fredrik Normen" <fredrik.normen@e...> on Sun, 15 Oct 2000 10:31:12 +0100
I have the same problem.

I think there is a bug, becuase I have to press on the ">" link twice to

see the next page, but when I done this there was no problem to go to the

next pages, but when I press the

"<" back link I didn't return to the previews page...



/Fredrik Normen

Message #3 by "Fredrik Normen" <fredrik.normen@e...> on Sun, 15 Oct 2000 20:52:29 +0100
Try to add this to your page.



<asp:Datagrid ....



   OnPageIndexChanged="DataGrid1_Page"



</asp:Datagrid>







Sub DataGrid1_Page(sender As Object, e As DataGridPageChangedEventArgs)

    DataGrid1.DataSource = ' Your datasource here.

    DataGrid1.DataBind

End Subī



/Fredrik Normen









Message #4 by "Fredrik Normen" <fredrik.normen@e...> on Sun, 15 Oct 2000 21:07:41 +0100
Here is how you sort on a filed in a datagrid:



Implement the DataGrid1_Sort function. This function takes the

DataGridSortCommandEventArgs E, which is passed in to it from the

OnSortCommand attribute in the DataGrid control, and passes it with a call

to BindGrid.



protected sub DataGrid1_Sort(Object Src, _ 

                             DataGridSortCommandEventArgs E) 

        BindGrid(E.SortField)

end sub



Implement the BindGrid function. The sortfield parameter (the sort column)

is passed to it from the DataGrid1_Sort function. It uses this information

to sort the table according to the specified column.



public sub BindGrid(String sortfield) 



Set up the SQLDataSetCommand to get the "Authors" table from the "pubs"

database.

        

SQLDataSetCommand myCommand = new SQLDataSetCommand

                               ("select * from Authors", myConnection)

Set up and fill a new DataSet. 

        Dim ds As DataSet= new DataSet()

        myCommand.FillDataSet(ds, "Authors")

Set up a DataView on the new DataSet, and sort the data using the

sortfield.

        Dim Source As DataView = ds.Tables("Authors").DefaultView

        Source.Sort = sortfield

Bind the DataGrid to the sorted DataView. 



DataGrid1.DataSource=Source

DataGrid1.DataBind()



The is an example about this in the ASP+ Quick Start.

Sample file DataGrid11.aspx



I hope this will help you about the sort thing.



/Fredrik Normen

Message #5 by "Fredrik Normen" <fredrik.normen@e...> on Mon, 16 Oct 2000 08:45:36 +0100
Here is an example how to use pages in the datagrid.



http://aspfree.com/asp+/demos/paging.aspx



/Fredrik Normen


  Return to Index