|
Subject:
|
paging for repeater control
|
|
Posted By:
|
abhishekkashyap27
|
Post Date:
|
4/16/2008 2:43:26 AM
|
Hi All
I am making a web application using C#,Sql Server 2005. I am using duwamish architecture, so i have three layers: one is GUI( cs page), Business Facade Layer( BF Layer), Data access Layer (DA).
Now first what have done by following a tutorial on net: I have declared three hidden controls :
<input type = "hidden" id = "PageSize" value = "3" runat = "server" /> <input type = "hidden" id = "CurrentPage" value = "1" runat = "server" /> <input type = "hidden" id = "TotalSize" runat = "server" />
And two link buttons:
<asp:LinkButton ID = "Prev" Text = "<<Previous" OnClick = "Page_Repeater" runat="server" /> <asp:LinkButton ID = "Next" Text = "Next>>" OnClick = "Page_Repeater" runat = "server" />
These are all in the design page:
For the Paging_Repeater function:
protected void Page_Repeater(object sender, EventArgs e) { if (((LinkButton)sender).ID == "Prev") //checking for button clicked { if ((int.Parse(CurrentPage.Value) - 1) >= 0) { CurrentPage.Value = (int.Parse(CurrentPage.Value) - 1).ToString(); } } else if (((LinkButton)sender).ID == "Next") { //checking if i can display the next page if ((int.Parse(CurrentPage.Value) * int.Parse(PageSize.Value)) < int.Parse(TotalSize.Value)) { // Incrementing the current page value CurrentPage.Value = (int.Parse(CurrentPage.Value) + 1).ToString(); } } FillRepeater(); } Now for the fillrepeater, i m connecting to DA( GUI->BF->DA) for connection. i am calling the stored procedure from da,retreiving records and then it is passed to BF, back to gui and here in Fill Repeater function, data is getting binded.
I want to restrict the no of records retreival in DA Layer only, here is one part(which i m using) of the DA:
public DataTable GetRptValuesDA(string strMode) { DataTable dtExitRt = new DataTable();
cmdExitRt = new SqlCommand("HR_SP_EXIT_CONS_RPT_GETDTLS", connExitRt); cmdExitRt.CommandType = CommandType.StoredProcedure;
//int StartRecord = (int.Parse(CurrentPage.Value) - 1) * int.Parse(PageSize.value); //daExitRt.Fill(dtExitRt, StartRecord, int.Parse(PageSize.Value), "Table");
cmdExitRt.Parameters.Add(new SqlParameter("@strMode", SqlDbType.Char, 1)); cmdExitRt.Parameters["@strMode"].Value = strMode;
daExitRt.SelectCommand = cmdExitRt; daExitRt.Fill(dtExitRt); return dtExitRt;
any idea guys how to restrict no of recors here in DA Layer itself ??????????
|
|
Reply By:
|
robzyc
|
Reply Date:
|
4/16/2008 2:51:18 AM
|
Although i have not used the Duwamish application for development, SQL is obviously getting executed on the server. Have you thought of updating your SP to use something like "SELECT TOP" to limit the results?
This sounds more like it is a SQL issue rather than C#? But I could be wrong, my experience with ASP.NET is limited! 
I think some of the other guys on the forum could really help you here 
Rob The Developing Developer Currently Working Towards: MCAD C# My Blog: http://robzyc.spaces.live.com
|
|
Reply By:
|
abhishekkashyap27
|
Reply Date:
|
4/16/2008 2:56:12 AM
|
Select top 2 from ...., in stored procedure will not work, because i cant restrict the no of records there, i have to fetch all the records and i have to restrict it using c#...,
-- Abhishek
|
|
Reply By:
|
robzyc
|
Reply Date:
|
4/16/2008 2:59:48 AM
|
Sounds awfully inefficient, but OK 
I would then say you need to lay a DataView over the table and sort/filter as necessary from there..
Rob The Developing Developer Currently Working Towards: MCAD C# My Blog: http://robzyc.spaces.live.com
|
|
Reply By:
|
abhishekkashyap27
|
Reply Date:
|
4/16/2008 4:22:13 AM
|
Hi Rob
As u have said,using a dataview it can be possible,can u show me code how to do it...
-- Abhishek
|
|
Reply By:
|
robzyc
|
Reply Date:
|
4/16/2008 4:35:17 AM
|
Hi Abhishek,
A DataView basically lays over the top of a DataTable and provides filtering and sort capabilities. Its normally inadvisable to use on large amounts of data, since it requires ALL the data to the client and then is filtered/sorted. However, you have said that that is not an option.
In terms of the code, well, there is plenty of resources on the Internet. And its covered in the foundations of any .NET training course..
Here are some links to help you get started, let us know if you have any problems trying to implement. I recommend checking in your source code before butchering your BLL/DAL 
http://msdn2.microsoft.com/en-us/library/system.data.dataview.aspx http://tinyurl.com/3z89m4
Or even better, try this one, may be a great place to start : http://tinyurl.com/3vmedd
At what point was it that developers lost the ability to research and think for themselves?! I seem to have missed it and feel like I am an odd one out 
Rob http://robzyc.spaces.live.com
|
|
Reply By:
|
abhishekkashyap27
|
Reply Date:
|
4/17/2008 4:38:28 AM
|
Hi Rob
DataView is failing for large amount of data. Well, i have implemented paging in my web app not using 'Repeater' but using GridView. Repeater supports paging when one is not using Duwamish Architecture(i.e when there is no GUI Layer, BF Layer, DA Layer). I tried a lot to implement paging using Repeater but gave up due to deadline.
Well folks , any one who have implemented paging using repeater( if web app is developed is using Duwamish architecture), please show me the light, because still i m excited to know how it can be done.
-- Abhishek
|
|
Reply By:
|
robzyc
|
Reply Date:
|
4/17/2008 4:48:45 AM
|
Hi Abhishek,
Sorry to hear the DataView couldnt help you out, this is why its very uncommon to have a view of ALL the data.
Maybe the more experienced ASP.NET guys can help you out, sadly, my knowledge of the ASP.NET controls is very limited.
Good luck 
Rob http://robzyc.spaces.live.com
|
|
Reply By:
|
lily611
|
Reply Date:
|
4/24/2008 3:28:30 AM
|
Hi Abhishek,
Can you please send me the code for gridview paging and sorting.
Thanks Lily
|
|
Reply By:
|
abhishekkashyap27
|
Reply Date:
|
4/25/2008 6:41:25 AM
|
Hi Lily
For GridView Paging, Here is the code: <asp:GridView ID="TestView" BorderWidth="0" Width="100%" CellPadding="2" CellSpacing="1" BackColor="#8BADBA" HeaderStyle-BackColor="#D8D8D8" runat="server" AutoGenerateColumns="False" ShowFooter="false" CssClass="bodytext" AllowPaging ="true" AllowSorting="true" ondatabound="TestView_DataBound" PageSize ="20" onpageindexchanged="TestView_PageIndexChanged" PagerStyle-HorizontalAlign="Center" PagerStyle-BackColor ="#ffffff" PagerStyle-CssClass ="url" OnPageIndexChanging ="TestView_PageIndexChanging"> <Columns> <asp:TemplateField AccessibleHeaderText="SlNo" HeaderText="SlNo" HeaderStyle-HorizontalAlign="center" HeaderStyle-BackColor="#D8D8D8" > <ItemStyle HorizontalAlign="center" BackColor="#ffffff" /> <ItemTemplate > <%#Container.DataItemIndex + 1%> </ItemTemplate> <FooterStyle HorizontalAlign="Center" BackColor="#ffffff" /> </asp:TemplateField> <asp:TemplateField HeaderText ="Emp No"> <ItemStyle HorizontalAlign="Justify" BackColor="#ffffff" /> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "empno") %> </ItemTemplate> </asp:TemplateField> ................ ................. </Columns> </asp:GridView>
Put these code in the design page under proper tr, td(HTML design controls) and customize it according to your need, well you can see the property allowpaging, set it to 'true',
Now to the code behind page:
write a function on page index changing: something like this: public void TestView_PageIndexChanging(Object sender, GridViewPageEventArgs e) {
..... ..... your code to retrieve the data ..... then... TestView.PageIndex = e.NewPageIndex; TestView.DataSource = dtTest .... (dtTest is datatable) TestView.DataBind();
if (Request.QueryString["Page"] != null) { TestView.PageIndex = e.NewPageIndex - 1; } else { TestView.PageIndex = e.NewPageIndex; }
TestView.PageSize = 20;
}
Well this is just the jist of code, you have to customize according to your need.
Hope this Helps... :)
-- Abhishek Kashyap
|