S
SAL
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
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