Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Paging in DataGrids

  Asked By: Jada    Date: Apr 02    Category: Asp.net    Views: 628
  

I am trying to implement caching for a Datagrid. I am using
System.Data.SqlClient as I habe SQL Server 2000 in the backend. Is it
possible to do caching without having a dataset. I am also including the
sample code below. If you can give some references where a Datagrid has been
implemented with pager controls, that would be great.


class ABC
{
private void Page_Load(object sender, System.EventArgs e)
{
if (this.Page.IsPostBack == false)
{
this.PopulateGrid();
dgCategorie.AllowPaging = true;
dgCategorie.PagerStyle.Mode =
PagerMode.NumericPages;
dgCategorie.PagerStyle.PageButtonCount = 5;
dgCategorie.PageSize = 10;
dgCategorie.VirtualItemCount = 200;
}
}

private void PopulateGrid()
{
Cat_Conn.Open();
strSQL = "Select Top 10 Cat_Nom, Coul_Cat, Tmpl_Cat
" +
"From Categories";
SqlCommand selCmd = new SqlCommand(strSQL,
Cat_Conn);
dgCategorie.DataSource =
selCmd.ExecuteReader(CommandBehavior.CloseConnection);
dgCategorie.DataBind();
Cat_Conn.Close();
}
}

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Archie Parker     Answered On: Apr 02

in your HTML you have to write:


<DataGrid
id=DataGrid1
AllowPaging="True"
PageSize="10" ' or other desired one
OnPageIndexChanged="DataGrid1_PageChanger"
>

Then you have to write a Public Sub DataGrid1_PageChanger:

Public Sub DataGrid2_PageChanger(ByVal objSender As Object, ByVal objArgs As DataGridPageChangedEventArgs)

... 'Get your data  From Database ...

DataGrid2.CurrentPageIndex = objArgs.NewPageIndex

' ... rebind data to datagrid  ...

DataGrid1.DataSource = myDataSet
DataGrid1.DataMember = "ArtikelTabel"
DataGrid1.DataBind()

End Sub

Implement something like this should work!

 
Didn't find what you were looking for? Find more on Paging in DataGrids Or get search suggestion and latest updates.




Tagged: