<asp:DataGrid ID="dg" Runat="server" BorderColor="#CC9966" BorderWidth="1px" AutoGenerateColumns="False"
Width="90%"
HorizontalAlign="Center"
AllowPaging="True"
PageSize="5"
PagerStyle-Visible="False" BackColor="White" BorderStyle="None"
CellPadding="4">
<HeaderStyle HorizontalAlign="Center" BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC"
/>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<PagerStyle Visible="False" BackColor="#FFFFCC" ForeColor="#330099"
HorizontalAlign="Center"></PagerStyle>
<ItemStyle />
<AlternatingItemStyle/>
<Columns>
<asp:BoundColumn HeaderText="regid"
DataField="regid" />
<asp:BoundColumn HeaderText="companyname"
DataField="companyname"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn HeaderText="address"
DataField="address"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
<br />
<table width="20%" border="0" align="center">
<tr>
<td align="center">
<input id="btnFirst" runat="server" type="button"
value="First"
onserverclick="btnFirst_ServerClick">
</td>
<td align="center">
<input id="btnPrev" runat="server" type="button"
value="Prev"
onserverclick="btnPrev_ServerClick">
</td>
<td align="center">
<input id="btnNext" runat="server" type="button"
value="Next"
onserverclick="btnNext_ServerClick">
</td>
<td align="center">
<input id="Last" runat="server" type="button"
value="Last"
onserverclick="btnLast_ServerClick">
</td>
</tr>
</table>
codebehind pages
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bindData();
}
}
protected void btnFirst_ServerClick(Object sender,EventArgs e)
{
if (dg.CurrentPageIndex > 0)
{ dg.CurrentPageIndex = 0;
bindData();
}
}
protected void btnPrev_ServerClick(Object sender,EventArgs e)
{
if (dg.CurrentPageIndex > 0)
{ dg.CurrentPageIndex -= 1;
bindData();
}
}
protected void btnNext_ServerClick(Object sender,EventArgs e)
{if (dg.CurrentPageIndex < dg.PageCount - 1)
{ dg.CurrentPageIndex += 1;
bindData();
}
}
protected void btnLast_ServerClick(Object sender,EventArgs e)
{
if (dg.CurrentPageIndex < dg.PageCount - 1)
{ dg.CurrentPageIndex = dg.PageCount - 1;
bindData();
}
}
private void bindData()
{
SqlConnection dbConn = new SqlConnection( ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("SELECT top 50 regid, companyname, address FROM registration ORDER BY companyname", dbConn);
DataSet dSet = new DataSet();
da.Fill(dSet);
dg.DataSource = dSet;
dg.DataBind();
}
GOOD
ReplyDelete