aspx Page
<asp:Repeater ID="rptPages" runat="server" OnItemCommand="rptPages_ItemCommand">
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tr class="text">
<td>
<b>Page:</b> </td>
<td>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="btnPage" CommandName="Page" CommandArgument="<%#
Container.DataItem %>" CssClass="text" runat="server"><%# Container.DataItem %>
</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
</td> </tr> </table>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater ID="rptItems" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="lblquestion" runat="server" Text="Question:" Font-Bold="True" ForeColor="Red"></asp:Label>
</td>
<td>
<asp:Label ID="lblques" runat="server" Text='<%#Eval("Question") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblans" runat="server" Text="Answer:" Font-Bold="True" ForeColor="Red"></asp:Label>
</td>
<td>
<asp:Label ID="lblanswer" runat="server" Text='<%#Eval("Answer") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
C# File
public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
return Convert.ToInt32(ViewState["PageNumber"]);
else
return 0;
}
set
{
ViewState["PageNumber"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
LoadData();
}
protected void rptPages_ItemCommand(object source, RepeaterCommandEventArgs e)
{
PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
LoadData();
}
private void LoadData()
{
DataTable dt = YatraGuruBL.Interface.Methods.Help.Get();
PagedDataSource pgitems = new PagedDataSource();
DataView dv = new DataView(dt);
pgitems.DataSource = dv;
pgitems.AllowPaging = true;
pgitems.PageSize = 3;
pgitems.CurrentPageIndex = PageNumber;
if (pgitems.PageCount > 1)
{
rptPages.Visible = true;
ArrayList pages = new ArrayList();
for (int i = 0; i < pgitems.PageCount; i++)
pages.Add((i + 1).ToString());
rptPages.DataSource = pages;
rptPages.DataBind();
}
else
rptPages.Visible = false;
rptItems.DataSource = pgitems;
rptItems.DataBind();
}
No comments:
Post a Comment