Thursday 29 November 2012

Paging, searching sorting using asp.net gridview

  UI Design:-

  Add ajax control toolkit at the top of page
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

  <form id="form1" runat="server">
     <asp:ToolkitScriptManager ID="toolManager" runat="server" />
    
    <div>
    <asp:UpdatePanel ID="updMain" runat="server"><ContentTemplate>
        <center>
                <div class="Subdiv" style="background-color: #DFDFDF;">
             <center>
            <asp:Table ID="Table1" runat="server"><asp:TableRow><asp:TableCell><asp:DropDownList ID="drplSearchType" Width="100" runat="server" /></asp:TableCell><asp:TableCell><asp:TextBox ID="txtTextSearch" AutoPostBack="true" runat="server" OnTextChanged="SearchTextChanged"/><asp:TextBoxWatermarkExtender
                    ID="TextBoxWatermarkExtender1" runat="server" WatermarkText="Search" TargetControlID="txtTextSearch" Enabled="true">
                </asp:TextBoxWatermarkExtender>
            </asp:TableCell><asp:TableCell><asp:ImageButton Width="20" Height="23" runat="server" ImageUrl="~/Images/search_button.png" BackColor="White" ID="imgbtnSearch" OnClick="imgbtnSearch_Click" /></asp:TableCell><asp:TableCell>&nbsp&nbsp&nbsp&nbsp&nbsp<asp:Label ID="lblPageNo" runat="server" Text="Page No." /><asp:DropDownList ID="drplPageNo" runat="server" Width="100" AutoPostBack="true" OnSelectedIndexChanged="drplPageNo_SelectedIndexChanged" /></asp:TableCell></asp:TableRow></asp:Table>
           
             </center>
            </div>
        </center>
        <center>
        <asp:UpdatePanel ID="UpdateGridview" runat="server">
         <ContentTemplate>
            <asp:GridView runat="server" ID="grdInventory" DataKeyNames="pkint_InventoryId" AutoGenerateColumns="False"
                      onsorting="grdInventory_Sorting1" width="890" AllowSorting="true"
                                    onrowcommand="grdInventory_RowCommand"><RowStyle BackColor="#EFF3FB" />
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <AlternatingRowStyle BackColor="White" />
                    <Columns>
                  
                     <asp:TemplateField SortExpression="pkint_InventoryId" HeaderText="InventoryId"
                            ItemStyle-HorizontalAlign="Center" ControlStyle-Width="100">
                            <HeaderStyle ForeColor="#E1E1FF" />
                            <ItemTemplate>
                                <asp:Label ID="lblInventoryId" Text='<%# Eval("EmpId") %>' Width="100" runat="server" /></ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Sub SectionId" SortExpression="fkint_SubSectionNo"
                             ControlStyle-Width="50" ItemStyle-HorizontalAlign="Center">
                             <HeaderStyle ForeColor="#E1E1FF" />
                            <ItemTemplate>
                                <asp:Label ID="lblSubSectionNo" Text='<%# Eval("EmpName") %>' Width="50" runat="server" /></ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="LocationId" ControlStyle-Width="100" SortExpression="fkint_LocationId"
                            ItemStyle-HorizontalAlign="Center">
                            <HeaderStyle ForeColor="#E1E1FF" />
                            <ItemTemplate>
                                <asp:Label ID="lblLocationId" Text='<%# Eval("EmpAddress") %>' Width="100" runat="server" /></ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>
                      

                     <asp:TemplateField HeaderText="Edit" ControlStyle-Width="25">
                    <ItemTemplate>
                    <asp:ImageButton ID="imgbtn" ImageUrl="~/Images/Edit.jpg" runat="server" OnClick="imgbtn_Click"  ToolTip="Edit" Width="25" Height="25" />
                    </ItemTemplate>
                    </asp:TemplateField>

                     <asp:TemplateField HeaderText="Delete" ControlStyle-Width="25">
                    <ItemTemplate>
                    <asp:ImageButton ID="imgDelete" ImageUrl="~/Images/imagesCA03VBLD.jpg"  ToolTip="Delete" runat="server" OnClick="imgDelete_Click" Width="25" Height="25"  />
                    </ItemTemplate>
                    </asp:TemplateField>

               </Columns>
</asp:GridView>

    <div style="width:893px; background-color: #D3E6EB;height:36px;">
    <asp:Table ID="Table2" runat="server"><asp:TableRow><asp:TableCell>
            <asp:ImageButton ID="btnSortFirst" Width="30" Height="30" 
                Text="First" Imageurl="~/Images/Button-Rewind-icon.png" Font-Bold="true" runat="server" ToolTip="First Record"
                onclick="btnSortFirst_Click"/>   </asp:TableCell><asp:TableCell><asp:ImageButton Width="30px" Height="30px"
                                        ID="btnSortPrevious" Text="Previous" ToolTip="Previous"
                runat="server" Font-Bold="true" ImageUrl="~/Images/go_previous_blue.png"
                onclick="btnSortPrevious_Click" /></asp:TableCell>
                <asp:TableCell><asp:ImageButton ID="btnSortNext" Font-Bold="true"  ToolTip="Next"  ImageUrl="~/Images/go_next_blue.png" Width="30" Height="30"
                 Text="Next" runat="server" onclick="btnSortNext_Click" /> </asp:TableCell><asp:TableCell>
            <asp:ImageButton Width="30px" Height="30px"  ToolTip="Last Record"
                              ID="btnSortLast" Text="Last" Font-Bold="true"
                 runat="server" onclick="btnSortLast_Click" ImageUrl="~/Images/Button-Fast-Forward-icon.png"/></asp:TableCell>
                               <asp:TableCell><asp:Label ID="lblCount" runat="server"/></asp:TableCell><asp:TableCell><asp:Label ID="lblSetIndex" CssClass="FooterText" Height="20" Text="Page Size" runat="server"/></asp:TableCell><asp:TableCell><asp:TextBox ID="txtPageSize" CssClass="footerDropList" runat="server" AutoPostBack="True"/></asp:TableCell><asp:TableCell><asp:ImageButton ID="imgbtnPageSize" runat="server" Width="30" Height="30" ImageUrl="~/Images/874420,1327419752,2.jpg" onclick="imgbtnPageSize_Click" ToolTip="Change Page Size"/>&nbsp&nbsp <asp:ImageButton ID="btnAdd" runat="server" Height="20" Width="20" ImageUrl="~/Images/Add-icon.png" ToolTip="Add New Record" CssClass="footerDropList" onclick="btnAdd_Click" /></asp:TableCell></asp:TableRow></asp:Table>
                          <br /><br />
           <asp:Label ID="lblErro" runat="server" Text="No more records available" Visible="false"  ForeColor="Red"/>
        </div>
        </ContentTemplate>
        </asp:UpdatePanel>
        </center>
        </ContentTemplate></asp:UpdatePanel>
       
        <center>
        <div>
            <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
            <asp:Button ID="btnShowAddpopup" runat="server" Style="display: none" />
            <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup"
                PopupControlID="pnlpopup" CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
            </asp:ModalPopupExtender><asp:Panel ID="pnlpopup" runat="server" BackColor="White" Width="400px" Style="display: none">
                <asp:UpdatePanel ID="UpdateModal" runat="server">
                    <ContentTemplate>
                       <table width="100%" style="width: 100%; height: 100%" cellpadding="0" cellspacing="0">
                            <tr style="background-color: #3568FF;">
                                <td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
                                    align="center">
                                    Emp Details </td></tr><tr>
                                <td align="right" style="width: 45%">
                                    <asp:Label ID="lblInventoryId" runat="server" Text="Inventory Id" />
                                </td>
                                <td>
                                    <asp:Label ID="lblInventoryIdval" runat="server"></asp:Label></td></tr><tr>
                                <td align="right">
                                    EmpId: </td><td>
                                    <asp:TextBox ID="EmpId" runat="server"></asp:TextBox></td></tr><tr>
                                <td align="right">
                                    EmpName: </td><td>
                                    <asp:TextBox ID="EmpName" runat="server" />
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                   EmpAdd: </td><td>
                                    <asp:TextBox ID="EmpAdd" runat="server" />
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>
                </asp:UpdatePanel>
                <table>
                    <tr>
                        <td>
                        </td>
                        <td>
                            <asp:Button ID="btnUpdate" CommandName="Update" runat="server" Text="Edit" OnClick="btnUpdate_Click" />
                            <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            <asp:ModalPopupExtender ID="AddPopup" runat="server" TargetControlID="btnShowAddpopup"
                PopupControlID="AddPanel" CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
            </asp:ModalPopupExtender><asp:Panel ID="AddPanel" runat="server" BackColor="White" Width="400px" Style="display: none">
                <asp:UpdatePanel ID="UpdateAddpopup" runat="server">
                    <ContentTemplate>
                        <table width="100%" style="width: 100%; height: 100%" cellpadding="0" cellspacing="0">
                            <tr style="background-color: #3568FF">
                                <td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
                                    align="center">
                                    Inventory Details </td></tr><tr>
                                <td align="right">
                                    SubSectionId: </td><td>
                                    <asp:TextBox ID="txtaSubsectionId" runat="server"></asp:TextBox></td></tr><tr class="RowMargin">
                                <td align="right">
                                    Location Id: </td><td>
                                    <asp:TextBox ID="txtaLocationId" runat="server" />
                                </td>
                            </tr>
                            <tr class="RowMargin">
                                <td align="right">
                                    Region Id: </td><td>
                                    <asp:TextBox ID="txtaRegionId" runat="server" />
                                </td>
                            </tr>
                            <tr class="RowMargin">
                                <td align="right">
                                    Inventory Name: </td><td>
                                    <asp:TextBox ID="txtaInventoryName" runat="server" />
                                </td>
                            </tr>
                            <tr class="RowMargin">
                                <td align="right">
                                    Asset Type: </td><td>
                                    <asp:TextBox ID="txtaAssetType" runat="server" />
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>
                </asp:UpdatePanel>
                <table>
                    <tr>
                        <td>
                        </td>
                        <td>
                            <asp:Button ID="btnAddPopup" CommandName="Add" runat="server" Text="ADD" OnClick="btnAddPopup_Click" />
                            <asp:Button ID="btnAddPopupCancel" runat="server" Text="Cancel" />
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            </div>
        </center>
        </div>
        <asp:Label ID="lblIndex" runat="server" />
        <asp:Label ID="lblLastCount" runat="server" />
    </form>



Style sheet:-
 <style type="text/css">
        .GridTitle
        {
            background: #3568FF;
            color: White;
            width: 890px;
            font-size: larger;
            font-weight: bold;
            height:25px;
        }
        .GridHeader
        {
            background:#45697C;
            height:30px;
        }
         .Subdiv
        {
            width:893px;
            height:30px;
        }
        .modalBackground
        {
            background-color: Gray;
            filter: alpha(opacity=60);
            opacity: 0.6;
            z-index: 10000;
        }
        .buttonOpacity
        {
            filter: alpha(opacity=60);
            opacity: 0.6;
        }
    </style>

Script:-

  <script type="text/javascript">
        function RefreshUpdatePanel() { __doPostBack('<%= txtTextSearch.ClientID %>', ''); };
    </script>




Code Behind :-
 public partial class test : System.Web.UI.Page
    {
 int Count;
        int PageNo;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                lblIndex.Text = "1";
                Session["PageStart"] = "1";
                Session["PageSize"] = "10";
                Session["SortExpression"] = "EmpId";
                Session["SortDirection"] = "ASC";


                drplSearchType.Items.Add("Search type");
                drplSearchType.Items.Add("All");
                drplSearchType.Items.Add("Emp Id");
                drplSearchType.Items.Add("EmpName");
                drplSearchType.Items.Add("EmpAddress");
                drplSearchType.SelectedIndex = 0;
                btnSortFirst.Enabled = false;
                btnSortPrevious.Enabled = false;
                objBL_Ienumerable = new BL_Ienumerable();
                grdInventory.DataSource = objBL_Ienumerable.Get_SPData(0, 10, Session["SortExpression"].ToString(), Session["SortDirection"].ToString(), 0, "", "", out Count, out PageNo);
                grdInventory.DataBind();
                Session["LastIndex"] = PageNo.ToString();
                Session["PageNo"] = PageNo.ToString();
                lblCount.Text = "0 to 10 of " + Count;
                txtPageSize.Text = "10";
                BindPageDropDownList(PageNo);
            }
        }

 private void BindPageDropDownList(int PageNo)
        {

            for (int i = 1; i <= PageNo; i++)
            {
                drplPageNo.Items.Add(i.ToString());
            }
        }
    private void BindGridview(int PageIndex, int PageSize, string SortExpression, string SortDirection, int NewPageIndex, string SearchText, string SearchType, out int Count, out int PageNo)
        {

            int IndexStart;
            int IndexEnd;
            objBL_Ienumerable = new BL_Ienumerable();
            grdInventory.DataSource = objBL_Ienumerable.Get_SPData(PageIndex, PageSize, SortExpression, SortDirection, NewPageIndex, SearchText, SearchType, out Count, out PageNo);
            grdInventory.DataBind();
            IndexStart = ((PageIndex * PageSize) - PageSize);
            IndexEnd = (PageIndex * PageSize);
            txtPageSize.ReadOnly = false;

            if (Count < PageSize && txtTextSearch.Text != "")
            {
                DisableNextButton(); DisablePreviousButton(); txtPageSize.ReadOnly = true;
                lblCount.Text = IndexStart + " to " + Count + " of " + Count;
                imgbtnPageSize.Enabled = false;
            }
            else if ((IndexStart + PageSize) >= Count)
            {
                lblCount.Text = (IndexStart + 1) + " to " + Count + " of " + Count;
                DisableNextButton();
                EnablePreviousButton();
                txtPageSize.ReadOnly = true;
                imgbtnPageSize.Enabled = false;
            }

            else if (PageIndex == 1)
            {
                lblCount.Text = (IndexStart + 1) + " to " + IndexEnd + " of " + Count;
                DisablePreviousButton();
                EnableNextButton();
                imgbtnPageSize.Enabled = true;
            }
            else
            {
                lblCount.Text = (IndexStart + 1) + " to " + IndexEnd + " of " + Count;
                EnableNextButton();
                EnablePreviousButton();
                imgbtnPageSize.Enabled = true;
            }
            lblIndex.Text = PageIndex.ToString();
            Session["sLast"] = PageNo.ToString();
            drplPageNo.Items.Clear();
            BindPageDropDownList(PageNo);
            if (PageNo > 0)
                drplPageNo.SelectedIndex = PageIndex - 1;
            //if(Convert.ToInt32(Session["PageStart"])!= 0)
            //    lblCount.Text = Convert.ToInt32(Session["PageStart"]) + " to " + (Convert.ToInt32(Session["PageStart"]) + Convert.ToInt32(txtPageSize.Text) -1) + " of " + Count;
            //else
            //    lblCount.Text = Convert.ToInt32(Session["PageStart"]) + " to " + (Convert.ToInt32(Session["PageStart"]) + Convert.ToInt32(txtPageSize.Text)) + " of " + Count;
        }


 #region Sorting Grdiview Column
        private string SortDirection
        {
            get
            {
                if (ViewState["SortDirection"] != null)
                    return (String)ViewState["SortDirection"];
                else return "ASC";
            }
            set
            {
                ViewState["SortDirection"] = value;
            }
        }
        private string SortExpression
        {
            get
            {
                if (ViewState["SortExpression"] != null)
                    return ViewState["SortExpression"].ToString();
                else return null;
            }
            set
            {
                ViewState["SortExpression"] = value;
            }
        }
        protected void grdInventory_Sorting1(object sender, GridViewSortEventArgs e)
        {
            Session["SortDirection"] = "DESC";
            Session["Index"] = "0";
            if (SortExpression != null)
            {
                if (SortExpression == e.SortExpression && SortDirection == "ASC")
                {
                    SortDirection = "DESC";
                    Session["SortDirection"] = "DESC";
                    DisablePreviousButton();
                }
                else
                {
                    SortDirection = "ASC";
                    Session["SortDirection"] = "ASC";
                }
            }
            SortExpression = e.SortExpression;
            Session["SortExpression"] = SortExpression.ToString();
            BindGridview(1, Convert.ToInt32(Session["PageSize"]), Session["SortExpression"].ToString(), Session["SortDirection"].ToString(), 0, "search", "col", out Count, out PageNo);

            EnableNextButton();
            DisablePreviousButton();
        }
        #endregion


#region Paging Buttons

        protected void btnSortFirst_Click(object sender, ImageClickEventArgs e)
        {
            lblIndex.Text = "1";
            BindGridview(Convert.ToInt32(lblIndex.Text), Convert.ToInt32(Session["PageSize"]), Session["SortExpression"].ToString(), Session["SortDirection"].ToString(), 0, txtTextSearch.Text, drplSearchType.Text, out Count, out PageNo);
            DisablePreviousButton(); EnableNextButton();
            //Session["PageStart"] = "1";
            lblErro.Visible = true;
            lblErro.Text = "No more records available, We are on First page";
        }

        protected void btnSortPrevious_Click(object sender, ImageClickEventArgs e)
        {
            int Index = Convert.ToInt32(lblIndex.Text);
            if (Index > 1)
            {
                Index = Convert.ToInt32(lblIndex.Text) - 1;
                BindGridview(Index, Convert.ToInt32(txtPageSize.Text), Session["SortExpression"].ToString(), Session["SortDirection"].ToString(), 0, txtTextSearch.Text, drplSearchType.Text, out Count, out PageNo);
                EnableNextButton();
                //Session["PageStart"] = (Convert.ToInt32(Session["PageStart"]) - Convert.ToInt32(txtPageSize.Text)).ToString();
                //int PageStart = Convert.ToInt32(Session["PageStart"]);
                //lblCount.Text = PageStart + " to " + (PageStart + Convert.ToInt32(txtPageSize.Text) - 1) + " of " + Count;
            }
            lblErro.Visible = false;
            if (Index == 1)
            {
                DisablePreviousButton();
                lblErro.Visible = true;
                lblErro.Text = "No more records available, We are on First page";
            }
            lblIndex.Text = Index.ToString();

        }

        protected void btnSortNext_Click(object sender, ImageClickEventArgs e)
        {
            int Index = Convert.ToInt32(lblIndex.Text);
            int Last = Convert.ToInt32(Session["LastIndex"]);

            //Session["PageStart"] = (Convert.ToInt32(Session["PageStart"]) + Convert.ToInt32(Session["PageSize2"]));
            Session["PageSize2"] = txtPageSize.Text;
            //Session["PageSize"] = (Convert.ToInt32(Session["PageSize"]) + Convert.ToInt32(txtPageSize.Text));
            if (Index < Last)
            {
                Index = Convert.ToInt32(lblIndex.Text) + 1;
                BindGridview(Index, Convert.ToInt32(Session["PageSize"]), Session["SortExpression"].ToString(), Session["SortDirection"].ToString(), 0, txtTextSearch.Text, drplSearchType.Text, out Count, out PageNo);
                EnablePreviousButton();
                //Session["PageStart"] = (Convert.ToInt32(Session["PageStart"]) + Convert.ToInt32(txtPageSize.Text)).ToString();
                //int PageStart = Convert.ToInt32(Session["PageStart"]);
                //lblCount.Text = PageStart + " to " + (PageStart + Convert.ToInt32(txtPageSize.Text) - 1) + " of " + Count;
            }
            lblErro.Visible = false;
            if (Index == Last)
            {
                DisableNextButton();
                txtPageSize.ReadOnly = true;
                lblErro.Text = "No more records available, We are on last page";
                lblErro.Visible = true;
            }
            lblIndex.Text = Index.ToString();

        }

        protected void btnSortLast_Click(object sender, ImageClickEventArgs e)
        {
            lblIndex.Text = Session["LastIndex"].ToString();
            BindGridview(Convert.ToInt32(lblIndex.Text), Convert.ToInt32(Session["PageSize"]), Session["SortExpression"].ToString(), Session["SortDirection"].ToString(), 0, txtTextSearch.Text, drplSearchType.Text, out Count, out PageNo);
            EnablePreviousButton(); DisableNextButton();
            //Session["PageStart"] = (Count - grdInventory.Rows.Count + 1).ToString();
            //int PageStart = Convert.ToInt32(Session["PageStart"]);
            txtPageSize.ReadOnly = true;
            lblErro.Visible = true;
            lblErro.Text = "No more records available, We are on last page";
        }
        #endregion

   #region Add New Record
        protected void btnAdd_Click(object sender, ImageClickEventArgs e)
        {
            this.AddPopup.Show();
            EmpName.Text = "";
            EmpAdd.Text = "";
        }
        #endregion


        protected void drplSetIndex_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

  #region Page size Button
        protected void imgbtnPageSize_Click(object sender, ImageClickEventArgs e)
        {
          
            lblIndex.Text = "1";//((PageSize * Index) / tbxPageSize).ToString();
            if (Convert.ToInt32(lblIndex.Text) == 0)
                lblIndex.Text = "1";
         
            Session["PageSize"] = Convert.ToInt32(txtPageSize.Text);
            Session["PageNo"] = PageNo.ToString();
            BindGridview(Convert.ToInt32(lblIndex.Text), Convert.ToInt32(txtPageSize.Text), Session["SortExpression"].ToString(), Session["SortDirection"].ToString(), 0, "search", drplSearchType.SelectedItem.Text, out Count, out PageNo);
            drplPageNo.Items.Clear();
            BindPageDropDownList(PageNo);
            Session["LastIndex"] = PageNo.ToString();
        }
        #endregion

        #region Button Enable and Disable Code
        public void DisableNextButton()
        {
            btnSortLast.Enabled = false;
            btnSortNext.Enabled = false;
        }
        public void EnableNextButton()
        {
            btnSortLast.Enabled = true;
            btnSortNext.Enabled = true;
        }
        public void DisablePreviousButton()
        {
            btnSortFirst.Enabled = false;
            btnSortPrevious.Enabled = false;
        }
        public void EnablePreviousButton()
        {
            btnSortFirst.Enabled = true;
            btnSortPrevious.Enabled = true;
        }
        #endregion


  #region Search TextBox

        protected void imgbtnSearch_Click(object sender, ImageClickEventArgs e)
        {
            lblIndex.Text = "1";
            Session["PageSize"] = txtPageSize.Text;
            if (txtTextSearch.Text != "")
            {
                BindGridview(Convert.ToInt32(lblIndex.Text), Convert.ToInt32(Session["PageSize"]), Session["SortExpression"].ToString(), Session["SortDirection"].ToString(), 0, txtTextSearch.Text, drplSearchType.SelectedItem.Text, out Count, out PageNo);
                drplPageNo.Items.Clear();
                BindPageDropDownList(PageNo);
                lblErro.Text = Count + " records search for given string";
                lblErro.Visible = true;
            }
            else
            {
                BindGridview(Convert.ToInt32(lblIndex.Text), Convert.ToInt32(Session["PageSize"]), Session["SortExpression"].ToString(), Session["SortDirection"].ToString(), 0, txtTextSearch.Text, drplSearchType.SelectedItem.Text, out Count, out PageNo);
                drplPageNo.Items.Clear();
                BindPageDropDownList(PageNo);
                lblErro.Visible = false;
            }
            Session["LastIndex"] = PageNo.ToString();
        }
        protected void SearchTextChanged(object sender, EventArgs e)
        {

        }
        #endregion


   protected void drplPageNo_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblIndex.Text = drplPageNo.SelectedItem.Text;
            BindGridview(Convert.ToInt32(lblIndex.Text), Convert.ToInt32(Session["PageSize"]), Session["SortExpression"].ToString(), Session["SortDirection"].ToString(), 0, txtTextSearch.Text, drplSearchType.SelectedItem.Text, out Count, out PageNo);
            int PageSize = PageNo;//((Convert.ToInt32(drplPageNo.SelectedItem.Text) * Convert.ToInt32(txtPageSize.Text)) - Convert.ToInt32(txtPageSize.Text) +1);
            Session["PageStart"] = PageSize.ToString();
            if ((Convert.ToInt32(lblIndex.Text) * Convert.ToInt32(txtPageSize.Text) >= Count))
            {
                lblErro.Text = lblErro.Text = "No more records available, We are on last page";
                lblErro.Visible = true;
            }
            else if ((Convert.ToInt32(lblIndex.Text) == 1))
            {
                lblErro.Text = lblErro.Text = "No more records available, We are on First page";
                lblErro.Visible = true;
            }
            else
                lblErro.Visible = false;
        }
   protected void imgbtn_Click(object sender, ImageClickEventArgs e)
        {
            btnUpdate.Text = "Edit";
            dtGetById = new DataTable();
            ImageButton btndetails = sender as ImageButton;
            lblInventoryIdval.Text = grdInventory.DataKeys[((GridViewRow)((Control)btndetails.NamingContainer)).RowIndex].Value.ToString();
            dtGetById = DL.GetById(lblInventoryIdval.Text);
            for (int i = 0; i < dtGetById.Rows.Count; i++)
            {
                lblInventoryIdval.Text = dtGetById.Rows[i][0].ToString();
                EmpName.Text = dtGetById.Rows[i][1].ToString();
                EmpAddredd.Text = dtGetById.Rows[i][2].ToString();
            }

            this.ModalPopupExtender1.Show();
        }


        protected void imgDelete_Click(object sender, ImageClickEventArgs e)
        {
            ImageButton btndetails = sender as ImageButton;
            objDL = new DL();
            objDL.DeleteRecords(grdInventory.DataKeys[((GridViewRow)((Control)btndetails.NamingContainer)).RowIndex].Value.ToString());
            BindGridview(Convert.ToInt32(lblIndex.Text), Convert.ToInt32(Session["PageSize"]), Session["SortExpression"].ToString(), Session["SortDirection"].ToString(), 0, txtTextSearch.Text, drplSearchType.SelectedItem.Text, out Count, out PageNo);
        }
        #endregion


       Good Luck.........



0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home