How to create Datapager Gridview in asp.net.

How to create Datapager Gridview using MCN.WebControls.dll file .


<%@ Register Assembly="MCN.WebControls" Namespace="MCN.WebControls" TagPrefix="mcn" %>

  <asp:UpdatePanel ID="updPanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<mcn:DataPagerGridView ID="gvProducts" runat="server" OnRowDataBound="RowDataBound"
AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" CssClass="datatable"
CellPadding="0" BorderWidth="0px" GridLines="None" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField HeaderText="ID" DataField="Emp_Id" SortExpression="Emp_Id" HeaderStyle-CssClass="first"
ItemStyle-CssClass="first">
<HeaderStyle CssClass="first" />
<ItemStyle CssClass="first" />
</asp:BoundField>
<asp:BoundField HeaderText="Name" DataField="Emp_Name" SortExpression="Emp_Name" />
<asp:BoundField HeaderText="Quantity" DataField="Emp_Payroll_No" SortExpression="Emp_Payroll_No" />
</Columns>
<PagerSettings Visible="False" />
<RowStyle CssClass="row" />
</mcn:DataPagerGridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT * FROM [tblemployee]"></asp:SqlDataSource>
<!-- Notice this is outside the GridView -->
<div class="pager">
<asp:DataPager ID="pager" runat="server" PageSize="8" PagedControlID="gvProducts">
<Fields>
<asp:NextPreviousPagerField ButtonCssClass="command" FirstPageText="«" PreviousPageText="‹"
RenderDisabledButtonsAsLabels="true" ShowFirstPageButton="true" ShowPreviousPageButton="true"
ShowLastPageButton="false" ShowNextPageButton="false" />
<asp:NumericPagerField ButtonCount="7" NumericButtonCssClass="command" CurrentPageLabelCssClass="current"
NextPreviousButtonCssClass="command" />
<asp:NextPreviousPagerField ButtonCssClass="command" LastPageText="" NextPageText="›"
RenderDisabledButtonsAsLabels="true" ShowFirstPageButton="false" ShowPreviousPageButton="false"
ShowLastPageButton="true" ShowNextPageButton="true" />
</Fields>
</asp:DataPager>
</div>
</ContentTemplate>
</asp:UpdatePanel>

in page_load if you write down

   protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
String strConnString = "Data Source=\\SqlExpress;Initial Catalog=HRDB;User ID=sa;";
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("tblemployee");
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlquery;

cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
gvProducts.DataSource = dt;
gvProducts.DataBind();
}

Ebook Download
View all
Learn
View all