Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
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.
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.