Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Repeater control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SAL - 30 Nov 2007 15:40 GMT
I have a web form that use the Repeater control on it.  Here is what the code
snippet looks like:

       <table class="collector" style="width: 870px">
           <asp:repeater id="repeaterItems" runat="server">
                <itemtemplate>
                   <tr>
                       <td class="logoColumn" colspan="1" style="width:
60px">
                           <img src="Images/user_headset.png" alt=""/></td>
                       <td class="tableHead" colspan="9" style="width:
820px">
                           Customer Group: <%=
DataHelper.SafeGetValue(this.CollectorDataSet, 0, 0, "Customer_Group")%>
                       </td>
                   </tr>
                </itemtemplate>
            </asp:repeater>

           <tr>
               <td style="width: 60px; height: 50px" class="bodyStyle2">
               </td>
               <td class="bodyStyle2" colspan="1" style="width: 726px;
height: 50px">
                   <asp:Button ID="cmdPrev" runat="server"
OnClick="cmdPrev_Click" Text=" <<  Previous " BackColor="White"
BorderColor="Blue" BorderStyle="Solid" BorderWidth="1px" ForeColor="Black"
Width="91px" /></td>
               <td class="statSubtitle1">
                   <asp:label id="lblCurrentPage" runat="server"
CssClass="statSubtitle1" Width="60px"></asp:label>
               </td>
               <td class="bodyStyle2" style="width: 98px; height: 50px">
                   <asp:Button ID="cmdNext" runat="server"
OnClick="cmdNext_Click" Text=" Next  >> " BackColor="White"
BorderColor="Blue" BorderStyle="Solid" BorderWidth="1px" ForeColor="Black"
Width="91px" />
               </td>
               <td class="bodyStyle2" style="width: 56px; height: 50px">
               </td>
           </tr>
       </table>

All examples I’ve seen use <%# DataBinder.Eval(Container.DataItem,
"Customer_Group") %> to bind data to the Repeater, but I am using my own
custom C# class that binds the repeater which works fine.  However, when I
click the Next button on my form it does not move to the next record.  It
keeps repeating the same record over and over even though my repeater control
is being binded with the correct record count.  I'm not sure if the
DataBinder and Container go hand in hand with the repeator and thats why my
the Next/Previous buttons don't move to the next record.  Here’s how I bind
the repeater:

   private void ItemsGet()
   {

       // Populate the repeater control with the Items DataSet
       PagedDataSource objPds = new PagedDataSource();
       objPds.DataSource = MyDataSet.Tables[0].DefaultView;
//Items.Tables[0].DefaultView;
       objPds.AllowPaging = true;
       objPds.PageSize = 1;

       objPds.CurrentPageIndex = CurrentPage;

       lblCurrentPage.Text = (CurrentPage + 1).ToString() + " of "
           + objPds.PageCount.ToString();

       // Disable Prev or Next buttons if necessary
       cmdPrev.Enabled = !objPds.IsFirstPage;
       cmdNext.Enabled = !objPds.IsLastPage;

       repeaterItems.DataSource = objPds;
       repeaterItems.DataBind();
   }

Here is the code for the Next Previous buttons

   protected void cmdPrev_Click(object sender, EventArgs e)
   {
       // Set viewstate variable to the previous page
       CurrentPage -= 1;

       // Reload control
       ItemsGet();

   }

   protected void cmdNext_Click(object sender, EventArgs e)
   {
       // Set viewstate variable to the next page
       CurrentPage += 1;

       // Reload control
       ItemsGet();
   }

   public int CurrentPage
   {
       get
       {
           // look for current page in ViewState
           object o = this.ViewState["_CurrentPage"];
           if (o == null)
               return 0;    // default to showing the first page
           else
               return (int)o;
       }

       set
       {
           this.ViewState["_CurrentPage"] = value;
       }
   }

Any suggestions would be helpful since I’ve programmed more in C# than
ASP.net.

Thanks
Nathan Sokalski - 01 Dec 2007 18:38 GMT
I have never written or seen anybody else write there own code to use in
place of DataBinder.Eval, but I would not recommend it anyway. Although one
thing I did notice is that you us <%= %> instead of <%# %>, which could be
having an effect on the repeating of the same data. Something else that I
noticed was that the following code:

<%=DataHelper.SafeGetValue(this.CollectorDataSet, 0, 0, "Customer_Group")%>

does not have anything that specifies which record to use, and since it does
not use <%# %> which have the specific purpose of being used for
databinding, I am not sure how your code would know what record to use. I
would recommend doing a debug session to see exactly what is happening at
each stage in the databinding. This is the best advice I can give, since I
have never seen anybody try to write a replacement for DataBinder.Eval and
although I know how to use databinding, I do not know a ton about the
internal coding of classes such as DataBinder.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

>I have a web form that use the Repeater control on it.  Here is what the
>code
[quoted text clipped - 120 lines]
>
> Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.