本文介绍了GridView如何在GridView中添加分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<pre lang="msil">public partial class POGrid : System.Web.UI.Page
{

   static DataSet ds;
   SqlConnection con = new SqlConnection(IMS.ConnectionString.getValue());

   protected void Page_Load(object sender, EventArgs e)
   {
       chkcreated.Visible = false;
       lblcreated.Visible = false;
       btnSaveCopy.Enabled = false;
       btnShowPO.Enabled = false;
       btnInvoicePO.Enabled = false;
       sessions.getsessions();
       if (!IsPostBack)
       {

       getpogrid();
      }
      }
   public static string getDateofBom(object p)
   {
    return p.ToString().Split('' '')[0];
   }
   public static string getstatus(object iscon, object isper, object isapp, object isinv, object ispaid, object pid)
   {
       SqlConnection coned=new SqlConnection(IMS.ConnectionString.getValue());
       //SqlDataAdapter da=new SqlDataAdapter("select count(*) from items_delete_po where purchase_id=''"+pid.ToString()+"'' and ",coned);
       //DataSet ds = new DataSet();
       //da.Fill(ds, "IDPo");
       //int cou = Convert.ToInt32(ds.Tables["IDPo"].Rows[0][0].ToString());

       if (Convert.ToBoolean(iscon) == false)
           return "Not conformed";
       else if (Convert.ToBoolean(iscon) == true && Convert.ToBoolean(isper) == false)
           return "Not performal";
       else if (Convert.ToBoolean(isper) == true && Convert.ToBoolean(isapp) == false)
           //if (cou > 0)
           //    return "Not Approved \n items are pending";
           //else
               return "Not Approved";
       else if (Convert.ToBoolean(isapp) == true && Convert.ToBoolean(isinv) == false)
           //if (cou > 0)
           //    return "Not invoiced \n items are pending";
           //else
           return "Not invoiced";
       else if (Convert.ToBoolean(isinv) == true && Convert.ToBoolean(ispaid) == false)
           //if (cou > 0)
           //    return "Not Paid \n items are pending";
           //else
           return "Not Paid";
       else
           //if (cou > 0)
           //    return " IsPaid \n items are pending";
           //else
           return "Paid";
     }
   public void getpogrid()
   {
   string query = "";

   if (Session["UTI"].ToString() == "UT107")
     {
   query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and po.supplier_id=''" + Session["UI"].ToString() + "'' and Po.IsConfirm=''true'' and po.total_price>0";
   btnShowPO.Visible = false;
       }
       else
       {
   btnInvoicePO.Visible = false;
           query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and po.total_price>0";
           if(Session["UTI"].ToString() == "UT101")
           {
           btnInvoicePO.Visible = true;
           }
       }
       SqlDataAdapter da = new SqlDataAdapter(query , con);
       ds = new DataSet();
       da.Fill(ds, "POGRID");
       GVPO.DataSource = ds.Tables["POGRID"];
       GVPO.DataBind();

       //<Added by Naresh>
   }

   protected void chkselect_CheckedChanged(object sender, EventArgs e)
   {
       foreach (GridViewRow gvr in GVPO.Rows)
       {
           Label Pid = (Label)gvr.FindControl("lblPOID");
           CheckBox chk = (CheckBox)gvr.FindControl("chkselect");
           if (chk.Checked == true)
           {
               IMSNiana.POId = Pid.Text;
               btnShowPO.Enabled = true;
               btnInvoicePO.Enabled = true;
               btnSaveCopy.Enabled = true;
               break;
           }
           else
           {
          btnShowPO.Enabled = false;
          btnInvoicePO.Enabled = false;

           }
       }
   }
   protected void btnShowPO_Click(object sender, EventArgs e)
   {

   }
   protected void GVPO_RowCreated(object sender, GridViewRowEventArgs e)
   {
       if(e.Row.RowType == DataControlRowType.DataRow)
       {
       e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor=''#EEFF00''");
       e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;");
       }
       if (e.Row.RowType == DataControlRowType.Pager)
       {
           GridViewRow gvr = e.Row;
           LinkButton lb = (LinkButton)gvr.Cells[0].FindControl("p0");
           lb.Command += new CommandEventHandler(lb_Command);
           lb = (LinkButton)gvr.Cells[0].FindControl("p1");
           lb.Command += new CommandEventHandler(lb_Command);
           lb = (LinkButton)gvr.Cells[0].FindControl("p2");
           lb.Command += new CommandEventHandler(lb_Command);
           lb = (LinkButton)gvr.Cells[0].FindControl("p4");
           lb.Command += new CommandEventHandler(lb_Command);
           lb = (LinkButton)gvr.Cells[0].FindControl("p5");
           lb.Command += new CommandEventHandler(lb_Command);
           lb = (LinkButton)gvr.Cells[0].FindControl("p6");
           lb.Command += new CommandEventHandler(lb_Command);
       }
       }
   public void lb_Command(object sender, CommandEventArgs e)
   {
       GVPO.PageIndex = Convert.ToInt32(e.CommandArgument) - 1;
      GVPO.DataSource = ds.Tables["POGRID"];
       GVPO.DataBind();
   }
 protected void GVPO_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       //if (e.Row.RowType == DataControlRowType.DataRow)
       //{
       //    e.Row.Attributes.Add("onmouseover", "MouseEvents(this, event)");
       //    e.Row.Attributes.Add("onmouseout", "MouseEvents(this, event)");

       //    //<AddedControl By Naresh>
       //}
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
           DataRowView drv = (DataRowView)e.Row.DataItem;

           if (drv[8].ToString() == "False")
           {
               e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#FA5858");
           }
           else if (drv[9].ToString() == "False")
           {
               e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#F78181");
           }
           else if (drv[10].ToString() == "False")
           {
               e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#F5D0A9");
           }
           else if (drv[11].ToString() == "False")
           {
               e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#81DAF5");
           }
           else if (drv[12].ToString() == "False")
           {
               e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#CEE3F6");
           }


       }


   }

protected void GVPO_DataBound(object sender, EventArgs e)
   {
       try
       {
           GridViewRow gvrow = GVPO.BottomPagerRow;
           Label lblcurrentpage = (Label)gvrow.Cells[0].FindControl("CurrentPage");
           lblcurrentpage.Text = Convert.ToString(GVPO.PageIndex + 1);
           int[] page = new int[7];
           page[0] = GVPO.PageIndex - 2;
           page[1] = GVPO.PageIndex - 1;
           page[2] = GVPO.PageIndex;
           page[3] = GVPO.PageIndex + 1;
           page[4] = GVPO.PageIndex + 2;
           page[5] = GVPO.PageIndex + 3;
           page[6] = GVPO.PageIndex + 4;
           for (int i = 0; i < 7; i++)
           {
               if (i != 3)
               {
                   if (page[i] < 1 || page[i] > GVPO.PageCount)
                   {
                       LinkButton lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("p" + Convert.ToString(i));
                       lnkbtn.Visible = false;
                   }
                   else
                   {
                       LinkButton lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("p" + Convert.ToString(i));
                       lnkbtn.Text = Convert.ToString(page[i]);
                       lnkbtn.CommandName = "PageNo";
                       lnkbtn.CommandArgument = lnkbtn.Text;


                   }
               }
           }
           if (GVPO.PageIndex == 0)
           {
               LinkButton lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("LinkButton1");
               lnkbtn.Visible = false;
               lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("LinkButton2");
               lnkbtn.Visible = false;

           }
           if (GVPO.PageIndex == GVPO.PageCount - 1)
           {
               LinkButton lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("LinkButton3");
               lnkbtn.Visible = false;
               lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("LinkButton4");
               lnkbtn.Visible = false;

           }
           if (GVPO.PageIndex > GVPO.PageCount - 5)
           {
               Label lbmore = (Label)gvrow.Cells[0].FindControl("nmore");
               lbmore.Visible = false;
           }
           if (GVPO.PageIndex < 4)
           {
               Label lbmore = (Label)gvrow.Cells[0].FindControl("pmore");
               lbmore.Visible = false;
           }
       }
       catch
       {
       }

   }


   protected void GVPO_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       GVPO.PageIndex = e.NewPageIndex;
       GVPO.DataSource = ds.Tables["POGRID"];
       GVPO.DataBind();

   }
   protected void chkAll_CheckedChanged(object sender, EventArgs e)
   {
       if (chkAll.Checked == true)
       {
           string query = "";
           HttpCookie c = Request.Cookies["_Auth"];
           if (/*c.Values["UTI"]*/Session["UTI"].ToString() == "UT107")
           {
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and po.supplier_id=''" + Session["UI"].ToString() + "'' and Po.IsConfirm=''true'' and po.total_price > 0";
               btnShowPO.Visible = false;
           }
           else
           {
               btnInvoicePO.Visible = false;
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and po.total_price > 0";
               if (Session["UTI"].ToString() == "UT101")
               {
                   btnInvoicePO.Visible = true;
               }
           }
           SqlDataAdapter da = new SqlDataAdapter(query, con);
           ds = new DataSet();
           da.Fill(ds, "POGRID");
           GVPO.DataSource = ds.Tables["POGRID"];
           GVPO.DataBind();
       }

   }

   protected void chkcreated_CheckedChanged(object sender, EventArgs e)
   {
       if (chkcreated.Checked == true)
       {
           string query = "";
           HttpCookie c = Request.Cookies["_Auth"];
           if (/*c.Values["UTI"]*/Session["UTI"].ToString() == "UT107")
           {
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and po.supplier_id=''" + Session["UI"].ToString() + "'' and Po.IsConfirm=''true'' and po.total_price>0";
               btnShowPO.Visible = false;
           }
           else
           {
               btnInvoicePO.Visible = false;
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and po.IsConfirm=''false'' and po.total_price>0";
               if (Session["UTI"].ToString() == "UT101")
               {
                   btnInvoicePO.Visible = true;
               }
           }
           SqlDataAdapter da = new SqlDataAdapter(query, con);
           ds = new DataSet();
           da.Fill(ds, "POGRID");
           GVPO.DataSource = ds.Tables["POGRID"];
           GVPO.DataBind();
       }
   }
   protected void chkConformed_CheckedChanged(object sender, EventArgs e)
   {
       if (chkConformed.Checked ==true)
       {
           string query = "";
           HttpCookie c = Request.Cookies["_Auth"];
           if (/*c.Values["UTI"]*/Session["UTI"].ToString() == "UT107")
           {
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and po.supplier_id=''" + Session["UI"].ToString() + "'' and Po.IsConfirm=''true'' and Isperformmal=''false'' and po.total_price>0";
               btnShowPO.Visible = false;
           }
           else
           {
               btnInvoicePO.Visible = false;
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and Po.IsConfirm=''true'' and Isperformmal=''false'' and po.total_price>0";
               if (Session["UTI"].ToString() == "UT101")
               {
                   btnInvoicePO.Visible = true;
               }
           }
           SqlDataAdapter da = new SqlDataAdapter(query, con);
           ds = new DataSet();
           da.Fill(ds, "POGRID");
           GVPO.DataSource = ds.Tables["POGRID"];
           GVPO.DataBind();
       }

   }
   protected void chkPerformal_CheckedChanged(object sender, EventArgs e)
   {
       if (chkPerformal.Checked == true)
       {
           string query = "";
           HttpCookie c = Request.Cookies["_Auth"];
           if (/*c.Values["UTI"]*/Session["UTI"].ToString() == "UT107")
           {
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and po.supplier_id=''" + Session["UI"].ToString() + "'' and Po.IsConfirm=''true'' and Isperformmal=''true'' and IsApproved=''false'' and po.total_price>0";
               btnShowPO.Visible = false;
           }
           else
           {
               btnInvoicePO.Visible = false;
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and Po.IsConfirm=''true'' and Isperformmal=''true'' and IsApproved=''false'' and po.total_price>0";
               if (Session["UTI"].ToString() == "UT101")
               {
                   btnInvoicePO.Visible = true;
               }
           }
           SqlDataAdapter da = new SqlDataAdapter(query, con);
           ds = new DataSet();
           da.Fill(ds, "POGRID");
           GVPO.DataSource = ds.Tables["POGRID"];
           GVPO.DataBind();

       }
   }
   protected void chkApproved_CheckedChanged(object sender, EventArgs e)
   {
       if (chkApproved.Checked == true)
       {
           string query = "";
           HttpCookie c = Request.Cookies["_Auth"];
           if (/*c.Values["UTI"]*/Session["UTI"].ToString() == "UT107")
           {
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and po.supplier_id=''" + Session["UI"].ToString() + "'' and Po.IsConfirm=''true'' and Isperformmal=''true'' and IsApproved=''true'' and Isinvoiced=''false'' and po.total_price>0";
               btnShowPO.Visible = false;
           }
           else
           {
               btnInvoicePO.Visible = false;
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and Po.IsConfirm=''true'' and Isperformmal=''true'' and IsApproved=''true'' and Isinvoiced=''false'' and po.total_price>0";
               if (Session["UTI"].ToString() == "UT101")
               {
                   btnInvoicePO.Visible = true;
               }
           }
           SqlDataAdapter da = new SqlDataAdapter(query, con);
           ds = new DataSet();
           da.Fill(ds, "POGRID");
           GVPO.DataSource = ds.Tables["POGRID"];
           GVPO.DataBind();
       }
   }
   protected void chkInvoiced_CheckedChanged(object sender, EventArgs e)
   {
       if (chkInvoiced.Checked == true)
       {
           string query = "";
           HttpCookie c = Request.Cookies["_Auth"];
           if (/*c.Values["UTI"]*/Session["UTI"].ToString() == "UT107")
           {
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and po.supplier_id=''" + Session["UI"].ToString() + "'' and Po.IsConfirm=''true'' and Isperformmal=''true'' and IsApproved=''true'' and Isinvoiced=''true'' and IsPaid=''false'' and po.total_price>0";
               btnShowPO.Visible = false;
           }
           else
           {
               btnInvoicePO.Visible = false;
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and Po.IsConfirm=''true'' and Isperformmal=''true'' and IsApproved=''true'' and Isinvoiced=''true'' and IsPaid=''false'' and po.total_price>0";
               if (Session["UTI"].ToString() == "UT101")
               {
                   btnInvoicePO.Visible = true;
               }
           }
           SqlDataAdapter da = new SqlDataAdapter(query, con);
           ds = new DataSet();
           da.Fill(ds, "POGRID");
           GVPO.DataSource = ds.Tables["POGRID"];
           GVPO.DataBind();
       }
   }
   protected void chkpaid_CheckedChanged(object sender, EventArgs e)
   {
       if (chkpaid.Checked == true)
       {
           string query = "";
           HttpCookie c = Request.Cookies["_Auth"];
           if (/*c.Values["UTI"]*/Session["UTI"].ToString() == "UT107")
           {
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and po.supplier_id=''" + Session["UI"].ToString() + "'' and Po.IsConfirm=''true'' and Isperformmal=''true'' and IsApproved=''true'' and Isinvoiced=''true'' and IsPaid=''true'' and po.total_price>0";
               btnShowPO.Visible = false;
           }
           else
           {
               btnInvoicePO.Visible = false;
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and Po.IsConfirm=''true'' and Isperformmal=''true'' and IsApproved=''true'' and Isinvoiced=''true'' and IsPaid=''true'' and po.total_price>0";
               if (Session["UTI"].ToString() == "UT101")
               {
                   btnInvoicePO.Visible = true;
               }
           }
           SqlDataAdapter da = new SqlDataAdapter(query, con);
           ds = new DataSet();
           da.Fill(ds, "POGRID");
           GVPO.DataSource = ds.Tables["POGRID"];
           GVPO.DataBind();
       }
   }

   protected void chkNotConformed_CheckedChanged(object sender, EventArgs e)
   {
       if (chkNotConformed.Checked== true)
       {
           string query = "";
           HttpCookie c = Request.Cookies["_Auth"];
           if (/*c.Values["UTI"]*/Session["UTI"].ToString() == "UT107")
           {
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and po.supplier_id=''" + Session["UI"].ToString() + "'' and Po.IsConfirm=''false'' and po.total_price>0";
               btnShowPO.Visible = false;

           }
           else
           {
               btnInvoicePO.Visible = false;
               query = "select po.purchase_id,po.purchase_date,Po.supplier_id,po.bom_id,po.total_price,po.shipping_type,ut.User_Name,B.bom_createdby,po.IsConfirm,po.Isperformmal,po.IsApproved,po.Isinvoiced,po.IsPaid from  purchaseOrder po,UserTable ut,bom B where po.supplier_id=ut.User_Id  and po.bom_id=b.bom_id and Po.IsConfirm=''false'' and po.total_price>0";
               if (Session["UTI"].ToString() == "UT101")
               {
                   btnInvoicePO.Visible = true;
               }
           }
           SqlDataAdapter da = new SqlDataAdapter(query, con);
           ds = new DataSet();
           da.Fill(ds, "POGRID");
           GVPO.DataSource = ds.Tables["POGRID"];
           GVPO.DataBind();
       }
   }
   protected void GVPO_SelectedIndexChanged(object sender, EventArgs e)
   {

   }
   protected void btnSaveCopy_Click(object sender, EventArgs e)
   {
<code><code><pre lang="xml"><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

    <style type="text/css">
        .style1
        {
            font-size: large;
        }
    </style>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
     <script type = "text/javascript">
         function MouseEvents(objRef, evt) {

             var checkbox = objRef.getElementsByTagName("input")[0];

             if (evt.type == "mouseover") {

                 objRef.style.backgroundColor = "aqua";

             }

             else {

                 if (checkbox.checked) {

                 objRef.style.backgroundColor = "aqua";

                 }

                 else if (evt.type == "mouseout") {

                     if (objRef.rowIndex % 2 == 0) {

                         //Alternating Row Color

                         objRef.style.backgroundColor = "white";

                     }

                     else {

                         objRef.style.backgroundColor = "#E6E6E6";

                     }

                 }

             }

         }

</script>
<%--<javascript added by Naresh></javascript>--%>
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/>

    <div class="contentHeader">
    <br />
    <br />
    <asp:Label ID="lblporders" Text="Purchase Orders" runat="server"></asp:Label>
    <hr />
    </div>
   <table align="right">
   <tr align ="center" style ="font-weight :bold ";>
   <td align ="center" >
 <%--  <added by naresh></added>--%>

   <asp:CheckBox ID="chkAll" runat="server" oncheckedchanged="chkAll_CheckedChanged"
           AutoPostBack="true"  BorderStyle ="None" />
       <asp:Label ID="lblAll" runat="server"
           Text="All" CssClass="padding5x"  ></asp:Label>
           <asp:MutuallyExclusiveCheckBoxExtender ID="chkall_chk" runat="server" TargetControlID="chkAll" Key="select"></asp:MutuallyExclusiveCheckBoxExtender>
             <asp:CheckBox ID="chkNotConformed" runat="server" AutoPostBack="True" oncheckedchanged="chkNotConformed_CheckedChanged"
            />
       <asp:Label ID="lblnotconfirm" runat="server"
           Text="Not Conformed" AutoPostBack="true" BackColor="#FA5858"
           CssClass="padding5x"></asp:Label>
           <asp:MutuallyExclusiveCheckBoxExtender ID="MutuallyExclusiveCheckBoxExtender7" runat="server" TargetControlID="chkNotConformed" Key="select"></asp:MutuallyExclusiveCheckBoxExtender>
   <asp:CheckBox ID="chkcreated" runat="server"
           oncheckedchanged="chkcreated_CheckedChanged" /><asp:Label ID="lblcreated"
           runat="server" BackColor="#363636"
           Text="created" AutoPostBack="true" CssClass="padding5x"></asp:Label>
            <asp:MutuallyExclusiveCheckBoxExtender ID="MutuallyExclusiveCheckBoxExtender1" runat="server" TargetControlID="chkcreated" Key="select"></asp:MutuallyExclusiveCheckBoxExtender>
       <asp:CheckBox ID="chkConformed" runat="server"
           oncheckedchanged="chkConformed_CheckedChanged" AutoPostBack="true"
           BorderStyle ="None" />
       <asp:Label ID="lblConformed" runat="server"
           Text="Conformed" BackColor="#F78181" CssClass="padding5x"></asp:Label>
            <asp:MutuallyExclusiveCheckBoxExtender ID="MutuallyExclusiveCheckBoxExtender2" runat="server" TargetControlID="chkConformed" Key="select"></asp:MutuallyExclusiveCheckBoxExtender>
            <asp:CheckBox ID="chkPerformal" runat="server"
           oncheckedchanged="chkPerformal_CheckedChanged" AutoPostBack="true"
           BorderStyle ="None"/>
       <asp:Label ID="lblPerformal" runat="server"
           Text="Performal" BackColor="#F5D0A9" CssClass="padding5x"></asp:Label>
            <asp:MutuallyExclusiveCheckBoxExtender ID="MutuallyExclusiveCheckBoxExtender3" runat="server" TargetControlID="chkPerformal" Key="select"></asp:MutuallyExclusiveCheckBoxExtender>
            <asp:CheckBox ID="chkApproved" runat="server"
           oncheckedchanged="chkApproved_CheckedChanged" AutoPostBack="true"
           BorderStyle ="None" />
       <asp:Label ID="lblApproved" runat="server"
           Text="Approved" BackColor="#81DAF5" CssClass="padding5x"></asp:Label>
            <asp:MutuallyExclusiveCheckBoxExtender ID="MutuallyExclusiveCheckBoxExtender4" runat="server" TargetControlID="chkApproved" Key="select"></asp:MutuallyExclusiveCheckBoxExtender>
            <asp:CheckBox ID="chkInvoiced" runat="server"
           oncheckedchanged="chkInvoiced_CheckedChanged" AutoPostBack="true"
           BorderStyle ="None"/>
       <asp:Label ID="lblInvoiced" runat="server"
           Text="Invoiced" BackColor="#CEE3F6" CssClass="padding5x"></asp:Label>
            <asp:MutuallyExclusiveCheckBoxExtender ID="MutuallyExclusiveCheckBoxExtender5" runat="server" TargetControlID="chkInvoiced" Key="select"></asp:MutuallyExclusiveCheckBoxExtender>
            <asp:CheckBox ID="chkpaid" runat="server"
           oncheckedchanged="chkpaid_CheckedChanged" AutoPostBack="true"
           BorderStyle ="None"  />
       <asp:Label ID="lblpaid" runat="server"
           Text="Paid" BackColor="#E6E6E6" CssClass="padding5x" ></asp:Label>
            <asp:MutuallyExclusiveCheckBoxExtender ID="MutuallyExclusiveCheckBoxExtender6" runat="server" TargetControlID="chkpaid" Key="select"></asp:MutuallyExclusiveCheckBoxExtender>
      <a href="ShipingPO.aspx?U=PO" id="btnShowPO_POGrid"  >
       <asp:Button ID="btnShowPO"
           runat="server" CssClass="addButton" Height="40px"
           Text="Show PO"  Font-Bold="True" /></a> <a href="ShipingPO.aspx?U=PO"  id="btnInvoicePO_PG"><asp:Button ID="btnInvoicePO" runat="server" Text="InvoicePO"
               CssClass="addButton" Font-Bold="True" Height="40px" /></a>

    <asp:Button ID="btnSaveCopy" runat="server" CssClass="button addButton" Font-Bold="True" Height="40px" onclick="btnSaveCopy_Click" Text="Print" />




   </td>
   </tr>
   </table>
      <table style="height:100px;  width: 100%; padding:10px;">
       <tr ><td align="center">
         <asp:GridView ID="GVPO" runat="server" AutoGenerateColumns="False" CssClass="datatable"
           GridLines="None" AllowPaging="True" CellPadding ="4" CellSpacing ="1"  style="margin-right: 50px"
            DataKeyNames="purchase_id"  Font-Size="Small" BackColor="#E6E6E6" ForeColor="#0B3861"
               Width ="100%"
               onrowcreated="GVPO_RowCreated" onrowdatabound="GVPO_RowDataBound"
               PageSize="15"
               ondatabound="GVPO_DataBound" onpageindexchanging="GVPO_PageIndexChanging"
               onselectedindexchanged="GVPO_SelectedIndexChanged">
           <AlternatingRowStyle BackColor="white" />
        <Columns><%--
            <asp:TemplateField ControlStyle-Width="15px">--%>
            <asp:TemplateField HeaderText="Select" ItemStyle-HorizontalAlign ="Center">
            <ItemTemplate> <asp:CheckBox ID="chkselect" runat="server"
                    oncheckedchanged="chkselect_CheckedChanged" AutoPostBack="true"/>
                <asp:MutuallyExclusiveCheckBoxExtender ID="chkselect_MutuallyExclusiveCheckBoxExtender"
                    runat="server" Enabled="True" Key="selectGrid" TargetControlID="chkselect">
                </asp:MutuallyExclusiveCheckBoxExtender>
                </ItemTemplate>
            </asp:TemplateField>
                <asp:TemplateField HeaderText="Purchase Order" ItemStyle-HorizontalAlign ="Center"  >
                    <ItemTemplate>
                      <asp:Label ID="lblPOID" runat="server" Text=''<%# Eval("purchase_id") %>''   CssClass ="paddingItemDes" ></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                 <asp:BoundField DataField="User_Name" HeaderText="Supplier"
                ItemStyle-CssClass ="paddingItemDes " ItemStyle-HorizontalAlign = "Left"  >
<ItemStyle HorizontalAlign="Left" CssClass="paddingItemDes "></ItemStyle>
            </asp:BoundField>
                 <asp:BoundField DataField="bom_id" HeaderText="Bom" ItemStyle-HorizontalAlign = "Center"/>
            <asp:BoundField DataField="total_price" HeaderText="Total Price"
                ItemStyle-CssClass ="paddingItemDes "  ItemStyle-HorizontalAlign ="Center">
<ItemStyle HorizontalAlign="Right" CssClass="paddingItemDes"></ItemStyle>
            </asp:BoundField>
            <asp:BoundField DataField="shipping_type" HeaderText="Shipping Type"   ItemStyle-HorizontalAlign ="Center" />
                <asp:BoundField DataField="bom_createdby" HeaderText="Bom CreateBy" ItemStyle-HorizontalAlign ="Center" />
                <asp:TemplateField  HeaderText="Bom Date" ItemStyle-HorizontalAlign ="Center">
                <ItemTemplate>
                <asp:Label ID="lblbomDate" runat="server" Text=''<%#getDateofBom(Eval("purchase_date")) %>'' CssClass = "paddingItemDes" />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField  HeaderText="Status">
                <ItemTemplate>
                <asp:Label ID="lblstatus0" runat="server"   Text=''<%# getstatus(Eval("IsConfirm"),Eval("Isperformmal"),Eval("IsApproved"),Eval("Isinvoiced"),Eval("IsPaid"),Eval("purchase_id")) %>''    itemstyle-horizantalalign = "centre" CssClass ="paddingItemDes "/>
                </ItemTemplate>
                </asp:TemplateField>

           <%-- <asp:BoundField DataField="confirmedby" HeaderText="confirmedby"  />--%>
        </Columns>
           <%--<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Right" CssClass="margin5x" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />--%>
<%--
            <old ></old>--%>


            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
              <PagerStyle BackColor="#2461BF"  HorizontalAlign="Right"    CssClass="paddingItemDes"  Width ="100%" Height ="25px"  />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
      <PagerTemplate>

        <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Page" CommandArgument="First" CssClass="Linkbutton">First</asp:LinkButton>
        <asp:Label ID="pmore" runat="server" Text=""></asp:Label>
        <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Page" CommandArgument="Prev" CssClass="Linkbutton">Pre</asp:LinkButton>
        <asp:LinkButton ID="p0" runat="server" CssClass="Linkbutton">LinkButton</asp:LinkButton>
        <asp:LinkButton ID="p1" runat="server" CssClass="Linkbutton">LinkButton</asp:LinkButton>
        <asp:LinkButton ID="p2" runat="server" CssClass="Linkbutton">LinkButton</asp:LinkButton>
        <asp:Label ID="CurrentPage" runat="server" Text="Label"  ForeColor ="#EEE000" Font-Size ="Medium" ></asp:Label>
        <asp:LinkButton ID="p4" runat="server" CssClass="Linkbutton">LinkButton</asp:LinkButton>
        <asp:LinkButton ID="p5" runat="server" CssClass="Linkbutton">LinkButton</asp:LinkButton>
        <asp:LinkButton ID="p6" runat="server" CssClass="Linkbutton">LinkButton</asp:LinkButton>
        <asp:LinkButton ID="LinkButton3" runat="server" CommandName="Page" CommandArgument="Next" CssClass="Linkbutton">Next</asp:LinkButton>
        <asp:Label ID="nmore" runat="server" Text=""></asp:Label>
        <asp:LinkButton ID="LinkButton4" runat="server" CommandName="Page" CommandArgument="Last" CssClass="Linkbutton">Last</asp:LinkButton>
</PagerTemplate>

     <%-- <added by naresh></added>--%>

    </asp:GridView></td> </tr>
    </table>
     <CR:CrystalReportViewer ID="CRVPO" runat="server"
         AutoDataBind="true" />
</asp:Content>



SqlCommand cmdPO =新的SqlCommand("POGeneration",con);
cmdPO.Parameters.AddWithValue("@ POID",IMSNiana.POId);
cmdPO.CommandType = CommandType.StoredProcedure;
SqlDataAdapter daPOPRint =新的SqlDataAdapter(cmdPO);
DataSet ds = new DataSet();
daPOPRint.Fill(ds);
ReportDocument rpd = new ReportDocument();
rpd.FileName = Server.MapPath("POList.rpt");
rpd.SetDataSource(ds.Tables [0]);
rpd.PrintToPrinter(1,true,0,0);
foreach(GVPO.Rows中的GridViewRow gvr)
{
CheckBox ch =(CheckBox)gvr.FindControl("chkselect");
如果(ch.Checked == true)
{
ch.Checked = false;
}
}
}



SqlCommand cmdPO = new SqlCommand("POGeneration", con);
cmdPO.Parameters.AddWithValue("@POID",IMSNiana.POId);
cmdPO.CommandType = CommandType.StoredProcedure;
SqlDataAdapter daPOPRint = new SqlDataAdapter(cmdPO);
DataSet ds = new DataSet();
daPOPRint.Fill(ds);
ReportDocument rpd = new ReportDocument();
rpd.FileName = Server.MapPath("POList.rpt");
rpd.SetDataSource(ds.Tables[0]);
rpd.PrintToPrinter(1, true, 0, 0);
foreach (GridViewRow gvr in GVPO.Rows)
{
CheckBox ch = (CheckBox)gvr.FindControl("chkselect");
if (ch.Checked == true)
{
ch.Checked = false;
}
}
}

推荐答案


这篇关于GridView如何在GridView中添加分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 07:58