Pages

Friday, December 9, 2011

Paging in List View Control

ASPX Code For DataList

<asp:DataList ID="DataListPainting" runat="server" BorderColor="black" CellPadding="3"
Font-Size="5px" Font-Names="Tahoma"
HeaderStyle-BackColor="#000000" RepeatColumns="5"
RepeatDirection="Horizontal" Width="730px">
<HeaderStyle Font-Size="16px" HorizontalAlign="Left" Height="15" ForeColor="White" />
<HeaderTemplate>
<p>
<font color="#484848" face="Impact">&nbsp;&nbsp;&nbsp;&nbsp;Painting Gallary </font></p>
<p>
&nbsp;</p>
</HeaderTemplate>
<HeaderStyle BackColor="#f0f0f0" Font-Names="Tahoma"></HeaderStyle>
<ItemStyle Width="243px" />
<ItemTemplate>
<table width="100%" style="margin-left: 0px; height: 200px">
<tr>
<td align="left" style="height: 100px; vertical-align: top">
<a href='<%# Eval("ImageUrl","Paintings/{0}")%>' rel="prettyPhoto[pp_gal]"
title='<%# Eval("ImageUrl") %>'>
<img src='<%# Eval("ImageUrl","Paintings/{0}")%>' width="120" height="100"
style="text-decoration: none; border-color: Gray; border-width: 1px; border-style: solid;"
alt="" />
</a>
</td>
</tr>
<tr>
<td align="left" style="font-family: Arial; font-size: 12px; font-weight: normal;
vertical-align: top; color: #484848; text-align: left;">
<%#Eval("PaintingName")%>

</td>
</tr>
<tr>
<td align="left" style="font-family: Arial; font-size: 11px; font-weight: normal;
vertical-align: top; color: #484848; text-align: left;">
Size: <%#Eval("PaintingWidth")%> * <%#Eval("PaintingHeight")%>

</td>
</tr>
<tr>
<td align="left" style="font-family: Arial; font-size: 11px; font-weight: normal;
vertical-align: top; color: #484848; text-align: left;">
Price: <%#Eval("PaintingPrice")%>
<div style="height: 10px">
</div>
</td>
</tr>
<tr>
<td align="left" style="font-family: Arial; font-size: 11px; font-weight: normal;
vertical-align: top; color: #484848; text-align: left;">
<asp:ImageButton ID="imgBtnBuy" runat="server" PostBackUrl='<%# "BuyPainting.aspx?Id="+Eval("ID")+"&Name="+Eval("PaintingName")+"&Price="+Eval("PaintingPrice")+"&Width="+Eval("PaintingWidth")+"&Height="+Eval("PaintingHeight")+"&Image="+ Eval("ImageUrl","Paintings/{0}") %>' />

</td>
</tr>

</table>
</ItemTemplate>
<AlternatingItemStyle Width="243px" />

</asp:DataList>



Aspx Paging Control Code


<asp:DataPager ID="DataPagerPainting" runat="server" PagedControlID="DataListPainting"
PageSize="5" OnPreRender="DataPagerPainting_PreRender">
<Fields>
<asp:NextPreviousPagerField ShowFirstPageButton="True" ShowNextPageButton="False" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ShowLastPageButton="True" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>





C# Code for Paging



protected void DataPagerPainting_PreRender(object sender, EventArgs e)
{

OleDbConnection con = new OleDbConnection(Connstring);
//Binding Building Data
DataSet ds = new DataSet();
string queryInsert = " Select * from tblPaintingDetails where IsSoldOut=0 order by ID";
OleDbCommand cmd = new OleDbCommand(queryInsert, con);


OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
DataSet data = new DataSet();
adp.Fill(data);


DataListPainting.DataSource = data;
DataListPainting.DataBind();

con.Close();

}




No comments:

Post a Comment