Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

view gridview every 20 pages

Status
Not open for further replies.

peac3

Technical User
Jan 17, 2009
226
AU
Hi guys,

I am trying to view the list of tables which contains thousand of records to do viewing page every 20 pages and here's what I have been trying

asp.net code
Code:
<asp:GridView ID="GridRefTable" runat="server" CssClass="mword" EnableViewState ="false" HeaderStyle-CssClass="viewprpstatustablehead" 
                PagerSettings-Mode="NextPrevious" PageSize ="20" CellSpacing="0" CellPadding="5" PagerSettings-Visible="true" AllowPaging ="true"  />

cs code
Code:
        private void View_Table()
        {
            RefTable = DropDownListRefTables.SelectedItem.Value;

            SqlConnection conn = new SqlConnection(CONST_CONN);

            String sql = "select top 100 * from " + RefTable;

            SqlCommand cmd = new SqlCommand(sql, conn);

            try
            {
                if (DropDownListRefTables.SelectedItem.Value == "")
                {
                    LabelRefTable.CssClass = "merror";
                    LabelRefTable.Text = "Please choose the reference table";
                }
                else
                {
                    conn.Open();
                    SqlDataReader reader = cmd.ExecuteReader();
                    GridRefTable.DataSource = reader;
                    GridRefTable.DataBind();
                    reader.Close();

                    conn.Close();
                    conn.Dispose();
                }
            }
            catch (Exception ex)
            {
                LabelRefTable.CssClass = "merror";
                LabelRefTable.Text = ex.Message;
            }

But I have got an error:
"The data source does not support server-side data paging."

I understand to collect the records from table into list collection first, but how to do dynamic list collection since I have list of many different tables which contains different number of columns?

Any input will be appreciated :)
 
Sample code

The grid code looks something like.
Code:
<asp:DataGrid runat="server" ID="dgCommunication" AutoGenerateColumns="false" AllowPaging="true" PageSize="20" AllowSorting="true" Width="900" OnPageIndexChanged="commGrid_Paging"
the code behind
Code:
protected void commGrid_Paging(object sender, DataGridPageChangedEventArgs e)
  {
     dgCommunication.CurrentPageIndex = e.NewPageIndex;
     LoadComGrid();
  }
[code]
The loadcomgrid method just requerys the datasource and binds it to the grid. 
So for your example you would set the currentpageindex to 20 greater than it is now, rather than the newpageindex.. or you could set it to newpageindex+20

HTH


Rob
 
Hi NoCoolHandle,

your code about this is error
Code:
        protected void commGrid_Paging(object sender, DataGridPageChangedEventArgs e)
        {
            GridRefTable.CurrentPageIndex = e.NewPageIndex;
            View_Table();
        }

Here's the error code
Code:
Error	5	'System.Web.UI.WebControls.GridView' does not contain a definition for 'CurrentPageIndex' and no extension method 'CurrentPageIndex' accepting a first argument of type 'System.Web.UI.WebControls.GridView' could be found (are you missing a using directive or an assembly reference?)

Looks like Gridview doesnt have extension CurrentPageIndex.
 
Yeah.. it might be an issue with the [blue]GridView[/blue]..
I tend to like the [blue]DataGrid[/blue] more as it seems to be more flexable..
I will do a quick dig and see if i can find anything for a GridView that does tthe same thing..
Sorry I missed the clue at the top the first view.
<asp:Gridview
 
Hmm, this is strange...

in VS2008 DataGrid doesn't exist anymore, only GridView hence I use it.

I'll try it tomorrow as today I'm on leave.

Thanks anyway for your help NoCoolHandle
 
Now that is interesting..
You could try using intellisense to get it..
I.e. start typing <asp:Datag and see if it fills it in.

Just for the heck of it check out this site

there is a TONE of stuff about customizing the datagrid.

Lots of other great stuff on asp.net and for that matter .net in general (silverlight etc..)

The cool thing is it is full of examples C# and VB.

Enjoy the next few days off..

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top