1.open visual studio 2010
2.Create one Visual Web part
3.paste the below code inside the visual Web part
Design Code :-
<div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div class="Employee_Info">
</div>
<hr />
<span class="FirstName">First Name : <%#Eval("FirstName") %></span>
<br></br>
<span class="LastName">Last Name : <%#Eval("LastName")%></span>
<br></br>
<span class="Age">Age : <%#Eval("Age")%></span>
<br></br>
<span class="Address">Address : <%#Eval("Address")%></span>
<br></br>
<span class="City">city : <%#Eval("City")%></span>
<br></br>
<span class="State">State : <%#Eval("state")%></span>
<br></br>
<span class="Country">Country : <%#Eval("Country")%></span>
<br></br>
</div>
</ItemTemplate>
</asp:Repeater>
<div style="overflow: hidden;">
<asp:Repeater ID="rptPages" runat="server"
onitemcommand="rptPages_ItemCommand1">
<ItemTemplate>
<asp:LinkButton ID="btnPage"
style="padding:1px 3px; margin:1px; background:#ccc; border:solid 1px #666; font:8pt tahoma;"
CommandName="Page" CommandArgument="<%# Container.DataItem %>"
runat="server"><%# Container.DataItem %>
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
<table>
<tr>
<td class="style1">
<asp:LinkButton ID="lnkBtnPrev" runat="server" onclick="lnkBtnPrev_Click" >Previous</asp:LinkButton>
</td>
<td class="style2">
</td>
<td class="style2">
<asp:LinkButton ID="lnkBtnNext" runat="server" onclick="lnkBtnNext_Click" >Next</asp:LinkButton>
</td>
</tr>
</table>
Cs Code :-
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadData();
}
}
private void LoadData()
{
SPSite site = new SPSite("-------"); //Site Collection Url
SPWeb web = site.OpenWeb();
SPList listofEmp = web.Lists["Employee"]; //ListName
SPListItemCollection col = listofEmp.GetItems();
DataTable dtEmp = col.GetDataTable();
int dtcount = dtEmp.Rows.Count;
PagedDataSource pgitems = new PagedDataSource();
System.Data.DataView dv = new System.Data.DataView(dtEmp);
pgitems.DataSource = dv;
pgitems.AllowPaging = true;
pgitems.PageSize = 1;
pgitems.CurrentPageIndex = PageNumber;
if (pgitems.PageCount > 1)
{
rptPages.Visible = true;
System.Collections.ArrayList pages = new System.Collections.ArrayList();
for (int i = 0; i < pgitems.PageCount; i++)
pages.Add((i + 1).ToString());
rptPages.DataSource = pages;
rptPages.DataBind();
if (dtcount - 1 == PageNumber)
{
lnkBtnNext.Visible = false;
}
else
{
lnkBtnNext.Visible = true;
}
if (PageNumber == 0)
{
lnkBtnPrev.Visible = false;
}
else
{
lnkBtnPrev.Visible = true;
}
}
else
rptPages.Visible = false;
Repeater1.DataSource = pgitems;
Repeater1.DataBind();
}
public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
return Convert.ToInt32(ViewState["PageNumber"]);
else
return 0;
}
set
{
ViewState["PageNumber"] = value;
}
}
protected void rptPages_ItemCommand1(object source, RepeaterCommandEventArgs e)
{
PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
LoadData();
}
protected void lnkBtnNext_Click(object sender, EventArgs e)
{
PageNumber++;
LoadData();
}
protected void lnkBtnPrev_Click(object sender, EventArgs e)
{
PageNumber--;
LoadData();
}
No comments:
Post a Comment