We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Problem(DataList)

hey there, In the FAQ of the DataList there was this Question: How to do Paging in DataList? I wrote the exact code in my application but the "previous" and "Next" LinkButtons are not working I don''t know why...Here''s the code..Plz anyone try it and tell me wht''s missing?? <%#DataBinder.Eval(Container.DataItem, "ProductID").ToString()%> <%#DataBinder.Eval(Container.DataItem, "ProductName").ToString()%>
<< >>
C# int intStart ; SqlConnection cn ; SqlDataAdapter da ; DataSet ds ; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if(!Page.IsPostBack ) { ViewState["Start"] = 0; bindList(); } } void bindList() { cn = new SqlConnection("server=localhost;uid=sa;pwd=;database=northwind"); da = new SqlDataAdapter("Select * from Products ", cn); ds = new DataSet(); intStart = (int)ViewState["Start"]; ViewState["pageSize"] = 14; da.Fill(ds, intStart,(int) ViewState["pageSize"], "Table"); DataList1.DataSource = ds; DataList1.DataBind(); } private void lnkPrevious_Click(object sender, System.EventArgs e) { intStart = (int) ViewState["Start"] -(int) ViewState["pageSize"]; ViewState["Start"] = intStart; if (intStart <= 0 ) { ViewState["Start"] = 0; } bindList(); } private void lnkNext_Click(object sender, System.EventArgs e) { int dlistcount = DataList1.Items.Count; intStart = (int) ViewState["Start"]+(int) ViewState["pageSize"]; ViewState["Start"] = intStart; if ( dlistcount < (int)ViewState["pageSize"] ) { ViewState["Start"] = (int)ViewState["Start"] - (int)ViewState["pageSize"]; } bindList(); }

2 Replies

AD Administrator Syncfusion Team February 11, 2006 12:50 PM UTC

Hi, Does it Not Paging or some behaviour Changes? Like the pageSize differs or something like that, paging was working for me when i tried , i was using dataset and update here , if you still have problem in this code Regards, Hari hey there, > >In the FAQ of the DataList there was this Question: > How to do Paging in DataList? >I wrote the exact code in my application but the "previous" and "Next" LinkButtons are not working I don''t know why...Here''s the code..Plz anyone try it and tell me wht''s missing?? > > > > > > > <%#DataBinder.Eval(Container.DataItem, "ProductID").ToString()%> > > <%#DataBinder.Eval(Container.DataItem, "ProductName").ToString()%> > > > > > > > > > > >
<< > > >> > >
> > > > > >C# > >int intStart ; > >SqlConnection cn ; > >SqlDataAdapter da ; > >DataSet ds ; > >private void Page_Load(object sender, System.EventArgs e) > >{ > > // Put user code to initialize the page here > > if(!Page.IsPostBack ) > > { > > ViewState["Start"] = 0; > > bindList(); > > } > >} > > > >void bindList() > >{ > > cn = new SqlConnection("server=localhost;uid=sa;pwd=;database=northwind"); > > da = new SqlDataAdapter("Select * from Products ", cn); > > ds = new DataSet(); > > intStart = (int)ViewState["Start"]; > > ViewState["pageSize"] = 14; > > da.Fill(ds, intStart,(int) ViewState["pageSize"], "Table"); > > DataList1.DataSource = ds; > > DataList1.DataBind(); > >} > > > >private void lnkPrevious_Click(object sender, System.EventArgs e) > >{ > > intStart = (int) ViewState["Start"] -(int) ViewState["pageSize"]; > > ViewState["Start"] = intStart; > > if (intStart <= 0 ) > > { > > ViewState["Start"] = 0; > > } > > bindList(); > >} > > > >private void lnkNext_Click(object sender, System.EventArgs e) > >{ > > int dlistcount = DataList1.Items.Count; > > intStart = (int) ViewState["Start"]+(int) ViewState["pageSize"]; > > ViewState["Start"] = intStart; > > if ( dlistcount < (int)ViewState["pageSize"] ) > > { > > ViewState["Start"] = (int)ViewState["Start"] - (int)ViewState["pageSize"]; > > } > > bindList(); > >} > > > > >


AD Administrator Syncfusion Team February 11, 2006 01:04 PM UTC

Hi Adel, I could see the problem because of this line if ( dlistcount < (int)ViewState["pageSize"] ) { } ignore this line and then try , you should be able to continue with paging, I havent tried. if the above doesnt work ,Update here. Regards, Hari

Loader.
Live Chat Icon For mobile
Up arrow icon