Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 16th, 2008, 02:43 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default paging for repeater control

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 ??????????

 
Old April 16th, 2008, 02:51 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old April 16th, 2008, 02:56 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

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

 
Old April 16th, 2008, 02:59 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old April 16th, 2008, 04:22 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Hi Rob

As u have said,using a dataview it can be possible,can u show me code how to do it...


-- Abhishek
 
Old April 16th, 2008, 04:35 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

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/lib....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 :D

Rob
http://robzyc.spaces.live.com
 
Old April 17th, 2008, 04:38 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

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

 
Old April 17th, 2008, 04:48 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old April 24th, 2008, 03:28 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Abhishek,

Can you please send me the code for gridview paging and sorting.


Thanks
Lily

 
Old April 25th, 2008, 06:41 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

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







Similar Threads
Thread Thread Starter Forum Replies Last Post
Help me with repeater control? forlife ASP.NET 2.0 Basics 1 July 14th, 2007 12:09 PM
Repeater Control Dhanapal General .NET 0 April 2nd, 2007 04:50 AM
Repeater control. rupen ASP.NET 1.0 and 1.1 Basics 1 October 14th, 2005 08:34 AM
Repeater Control abdul_owiusa General .NET 0 August 30th, 2005 04:54 PM
Repeater Control Dmitriy Pro VB 6 0 July 27th, 2004 11:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.