Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 27, 2012 07:35 AM by anujtripathi
Member
7 Points
36 Posts
Feb 27, 2012 05:47 AM|LINK
hi all,
I want to do paging in datalist ,I alraedy did it with pagedatasource but my page take to much time to load .
pls help me for this or any other option of paging in datalist
void BindGetQuestions() { try { BuisnessLayer.Survey objSurvey = new BuisnessLayer.Survey();
//objSChoice.QuestionID = drpQuestion.SelectedValue; //objSChoice.Choice = rdoChoice.SelectedValue; //objSChoice.CreatedBy = "jaya"; DataSet ds = new DataSet(); // ds = objSurvey.GetQuestions(objSurvey); objSurvey.ClientID = "C000001"; ds = objSurvey.GetQuestionsByClientID(objSurvey); ViewState["dsQuestions"] = ds; if (ds.Tables[0].Rows.Count > 0) { DataList1.DataSource = ds; DataList1.DataBind(); } //paging DataTable dt = new DataTable(); dt = ds.Tables[0]; Session["Count"] = dt.Rows.Count;
if (ds!=null) { DataView dv = new DataView(dt); pds.DataSource = dv; pds.AllowPaging = true; pds.PageSize = 5; pds.CurrentPageIndex = CurrentPage; ViewState["TotalPages"] = pds.PageCount; //this.lblPageInfo.Text = "Page " + (CurrentPage + 1) + " of " + pds.PageCount; //.lblPageInfo.Text = "Page " + (CurrentPage + 1) + " of " + pds.PageCount; this.lnkbtnNext.Visible = !pds.IsLastPage; this.lnkbtnPrevious.Visible = !pds.IsFirstPage;
DataList1.DataSource = pds; DataList1.DataBind();
//lblCOunt.Text = Session["Count"].ToString(); if (pds.PageCount > 1) { //btngopage.Visible = true; // dlPaging.Visible = true; } else { // btngopage.Visible = false; // dlPaging.Visible = false; } tr1.Visible = true; } else { DataView dv = new DataView(null); pds.DataSource = null; pds.AllowPaging = true; pds.PageSize = 5; pds.CurrentPageIndex = CurrentPage; ViewState["TotalPages"] = pds.PageCount; // this.lblPageInfo.Text = "<font color=red size=2>No results found.</font>"; DataList1.DataSource = null; DataList1.DataBind(); //lblCOunt.Text = ""; lnkbtnNext.Visible = false; lnkbtnPrevious.Visible = false; // btngopage.Visible = false; // dlPaging.Visible = false; tr1.Visible = false; } doPaging(); } catch (Exception e) { } }
private void doPaging() { DataTable dt = new DataTable(); dt.Columns.Add("PageIndex"); dt.Columns.Add("PageText"); fistIndex = CurrentPage - 8; if (CurrentPage > 8) { lastIndex = CurrentPage + 8; } else { lastIndex = Convert.ToInt32(ViewState["TotalPages"]); }
if (lastIndex > Convert.ToInt32(ViewState["TotalPages"])) { lastIndex = Convert.ToInt32(ViewState["TotalPages"]); fistIndex = lastIndex - Convert.ToInt32(ViewState["TotalPages"]); } if (fistIndex < 0) {
fistIndex = 0;
} for (int i = fistIndex; i < lastIndex; i++) { DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = i + 1;
dt.Rows.Add(dr); } }
I have only 40 questions in database..not so much data then y page taking so much time foe loading?
please help me,its urgent
thanks in adv.
Contributor
3759 Points
595 Posts
Feb 27, 2012 07:35 AM|LINK
How many records are you displaying? Is there any complex logic in RowDataBound event?
See if there is any possibility to tweak the performance of datalist.
The other option is to use data paging, which will definetly increase the performace.
Below is the superb one stop example of doing that
http://weblogs.asp.net/scottgu/archive/2006/01/07/434787.aspx
another
http://weblogs.asp.net/scottgu/archive/2006/01/01/434314.aspx
jayaravi
Member
7 Points
36 Posts
datalist paging create performance of page loading
Feb 27, 2012 05:47 AM|LINK
hi all,
I want to do paging in datalist ,I alraedy did it with pagedatasource but my page take to much time to load .
pls help me for this or any other option of paging in datalist
void BindGetQuestions()
{
try
{
BuisnessLayer.Survey objSurvey = new BuisnessLayer.Survey();
//objSChoice.QuestionID = drpQuestion.SelectedValue;
//objSChoice.Choice = rdoChoice.SelectedValue;
//objSChoice.CreatedBy = "jaya";
DataSet ds = new DataSet();
// ds = objSurvey.GetQuestions(objSurvey);
objSurvey.ClientID = "C000001";
ds = objSurvey.GetQuestionsByClientID(objSurvey);
ViewState["dsQuestions"] = ds;
if (ds.Tables[0].Rows.Count > 0)
{
DataList1.DataSource = ds;
DataList1.DataBind();
}
//paging
DataTable dt = new DataTable();
dt = ds.Tables[0];
Session["Count"] = dt.Rows.Count;
if (ds!=null)
{
DataView dv = new DataView(dt);
pds.DataSource = dv;
pds.AllowPaging = true;
pds.PageSize = 5;
pds.CurrentPageIndex = CurrentPage;
ViewState["TotalPages"] = pds.PageCount;
//this.lblPageInfo.Text = "Page " + (CurrentPage + 1) + " of " + pds.PageCount;
//.lblPageInfo.Text = "Page " + (CurrentPage + 1) + " of " + pds.PageCount;
this.lnkbtnNext.Visible = !pds.IsLastPage;
this.lnkbtnPrevious.Visible = !pds.IsFirstPage;
DataList1.DataSource = pds;
DataList1.DataBind();
//lblCOunt.Text = Session["Count"].ToString();
if (pds.PageCount > 1)
{
//btngopage.Visible = true;
// dlPaging.Visible = true;
}
else
{
// btngopage.Visible = false;
// dlPaging.Visible = false;
}
tr1.Visible = true;
}
else
{
DataView dv = new DataView(null);
pds.DataSource = null;
pds.AllowPaging = true;
pds.PageSize = 5;
pds.CurrentPageIndex = CurrentPage;
ViewState["TotalPages"] = pds.PageCount;
// this.lblPageInfo.Text = "<font color=red size=2>No results found.</font>";
DataList1.DataSource = null;
DataList1.DataBind();
//lblCOunt.Text = "";
lnkbtnNext.Visible = false;
lnkbtnPrevious.Visible = false;
// btngopage.Visible = false;
// dlPaging.Visible = false;
tr1.Visible = false;
}
doPaging();
}
catch (Exception e)
{
}
}
private void doPaging()
{
DataTable dt = new DataTable();
dt.Columns.Add("PageIndex");
dt.Columns.Add("PageText");
fistIndex = CurrentPage - 8;
if (CurrentPage > 8)
{
lastIndex = CurrentPage + 8;
}
else
{
lastIndex = Convert.ToInt32(ViewState["TotalPages"]);
}
if (lastIndex > Convert.ToInt32(ViewState["TotalPages"]))
{
lastIndex = Convert.ToInt32(ViewState["TotalPages"]);
fistIndex = lastIndex - Convert.ToInt32(ViewState["TotalPages"]);
}
if (fistIndex < 0)
{
fistIndex = 0;
}
for (int i = fistIndex; i < lastIndex; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = i + 1;
dt.Rows.Add(dr);
}
}
I have only 40 questions in database..not so much data then y page taking so much time foe loading?
please help me,its urgent
thanks in adv.
anujtripathi
Contributor
3759 Points
595 Posts
Re: datalist paging create performance of page loading
Feb 27, 2012 07:35 AM|LINK
How many records are you displaying? Is there any complex logic in RowDataBound event?
See if there is any possibility to tweak the performance of datalist.
The other option is to use data paging, which will definetly increase the performace.
Below is the superb one stop example of doing that
http://weblogs.asp.net/scottgu/archive/2006/01/07/434787.aspx
another
http://weblogs.asp.net/scottgu/archive/2006/01/01/434314.aspx
Please remember to click “Mark as Answer” on the post that helps you, it will help other(s) to get there answer.