Click here to Skip to main content
15,918,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ProductGrid.aspx.cs" Inherits="ProductGrid" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
 <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <br />
    <asp:Label ID="LblNav" runat="server" Text="Product -" Font-Bold="true" Font-Size ="Small"  ForeColor ="Maroon">
    <asp:Label ID="Label1" runat="server" Text="List Of Products" Font-Bold="true" Font-Size ="X-Small"  ForeColor ="blue">
    <div class="contentHeader">
        <br />
        <br />
        <asp:Label ID="lbllistofprd" Text="List of Products" runat="server" >
        <hr />
    </div>
    <table align="right">
   <%--Added default button--%>
        <tr>
            <td>
                <asp:Button ID="btn_show_ProductDetails" runat="server" Text=" Show Items " CssClass="button" 
           Height="40px" Font-Bold="True"  
           Enabled="False" Width="120px" OnClientClick="return displayFancybox('showproductdetails.aspx');" />
                <%----%>
            </td>
            <td>
       <%--<a id="btn_addProductdetails_link" href="/KB/answers/ProductItemsDetails.aspx"></a>--%>
                <asp:Button ID="btn_addProductDetails" runat="server" Text=" + Add Items " CssClass="button" 
           Height="40px" Font-Bold="True"    
           Enabled="False" Width="120px" OnClientClick="return displayFancybox('ProductItemsDetails.aspx');" />
                <%----%>
            </td>
   <%--<td>
  <a id="various4" href="/KB/answers/ProductItemsDetails.aspx">
       <asp:ImageButton ID="imgaddproductdetails" runat="server" 
           ImageUrl="~/images/add.JPG"  ToolTip="Add Product Details" Width="25px"></a>
   </td>
   --%>
            <td>
                <asp:Button ID="btn_addNewProduct" 
            runat="server" Text="+ Add New Product" CssClass="addButton"
            Font-Bold="True" Height="40px" OnClientClick="return displayFancybox('NewProduct.aspx');" />
            </td>
   <%--<td><a id="various" href="/KB/answers/NewProduct.aspx"><asp:ImageButton ID="Imgaddnewproduct" runat="server" ImageUrl="~/images/addproduct.jpg" ToolTip="Add New Product" Width="35px"></a>
    </td>--%>
            <td>
                <asp:Button ID="btn_delProduct" runat="server" Text=" X Delete " CssClass="button"
            Font-Bold="True" Height="40px"  
            Enabled="False" Width="100px" onclick="btn_delProduct_Click1">
                <asp:ConfirmButtonExtender ID="btn_delProduct_ConfirmButtonExtender" 
            runat="server" ConfirmText="Are you sure to delete product" Enabled="True" TargetControlID="btn_delProduct">
                
            </td>
            <td>
                <asp:Button ID="btnUpdate" 
                    runat="server" Text="Edit" CssClass="button"
            Font-Bold="True" Height="40px" Width="100px" 
                    Enabled="False" OnClientClick="return displayFancybox('NewProduct.aspx?U=');" >
                
            </td>
                      <%--<td><asp:ImageButton ID="imgdelete" runat="server" ImageUrl="~/images/delete.bmp" ToolTip="DELETE" Width="25px" /></td>--%>
        </tr>
    </table>
    <table style="height:100px;  width: 100%; padding:10px;">
        <tr>
            <td align="center">
                <asp:GridView ID="GVProduct" runat="server" AutoGenerateColumns="False" CssClass="datatable "   
               GridLines ="None"  style="margin-right: 50px" CellPadding="4" CellSpacing="1"  
               Font-Size="Small" BackColor="#E6E6E6" ForeColor="#0B3861" 
               AllowPaging="True" PageSize ="15" 
               Width="100%" 
                 onrowcreated="GVProduct_RowCreated" 
               onrowdatabound="GVProduct_RowDataBound" ondatabound="GVProduct_DataBound" 
               onpageindexchanging="GVProduct_PageIndexChanging1" 
               onselectedindexchanged="GVProduct_SelectedIndexChanged" >
                    <%--   onselectedindexchanged="GVProduct_SelectedIndexChanged" >--%>
                    <alternatingrowstyle backcolor="White" />
                    <%--<add by="" naresh="" önpageindexchanging="GVProduct_PageIndexChanging"></add>--%>
                    <columns>
                        <asp:TemplateField ControlStyle-Width="15px" ItemStyle-HorizontalAlign="Center">
                            <HeaderTemplate>
                                Select
                            </HeaderTemplate>
                            <itemtemplate>
                                <asp:CheckBox ID="chkselect" runat="server"  AutoPostBack="true" 
                OnCheckedChanged="chkselect_CheckedChanged" />
                                <asp:MutuallyExclusiveCheckBoxExtender ID="chkselect_MutuallyExclusiveCheckBoxExtender" 
                runat="server" Enabled="True"  Key="gridchk" TargetControlID="chkselect">
                                
                            </itemtemplate>
                            <controlstyle width="15px"></controlstyle>
                        
                        <asp:TemplateField HeaderText="Product Name" ItemStyle-HorizontalAlign="Left">
                            <itemtemplate>
                                <asp:Label ID="productname" Text='<%# Eval("product_name") %>' runat="server" CssClass="paddingItemDes">
                            </itemtemplate>
                        
                        <asp:BoundField DataField="product_description" 
                HeaderText="Product Description" SortExpression="roduct_description" 
              ItemStyle-HorizontalAlign="Left" ItemStyle-CssClass="paddingItemDes" >
                        <itemstyle horizontalalign="Left" cssclass="paddingItemDes"></itemstyle>
                        
                        <%--Added by Raju to enhance the richness of UI--%>
                        <asp:TemplateField HeaderText="In Stock" ItemStyle-HorizontalAlign="Center">
                            <itemtemplate>
                                <asp:Label ID="instock" runat="server"                         
                        Text='<%# Eval("Stock") %>'>
                            </itemtemplate>
                        
                        <asp:TemplateField HeaderText="Committed" ItemStyle-HorizontalAlign="Center">
                            <itemtemplate>
                                <asp:Label ID="committed" runat="server" 
                        Text='<%# Eval("Commited") %>'>
                            </itemtemplate>
                        
                        <asp:TemplateField HeaderText="On Order" ItemStyle-HorizontalAlign="Center">
                            <itemtemplate>
                                <asp:Label ID="onorder" runat="server" 
                        Text='<%# Eval("Inorder") %>'>
                            </itemtemplate>
                        
                        <asp:TemplateField HeaderText="Wholesale" ItemStyle-HorizontalAlign="Center">
                            <itemtemplate>
                                <asp:Label ID="wholesale" runat="server" 
                        Text='<%# Eval("wholesalePrice") %>'>
                            </itemtemplate>
                        
                    </columns>
                    <footerstyle backcolor="#507CD1" font-bold="True" forecolor="White" />
                    <%--    <pagerstyle backcolor="#0078AE" horizontalalign="Right" cssclass="margin5x " />--%>
                    <pagerstyle backcolor="#0078AE" 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="#0078AE" />
                    <alternatingrowstyle backcolor="White" />
                    <pagertemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Page" CommandArgument="First" CssClass="Linkbutton">First
                        <asp:Label ID="pmore" runat="server" Text="">
                        <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Page" CommandArgument="Prev" CssClass="Linkbutton">Pre
                        <asp:LinkButton ID="p0" runat="server" CssClass="Linkbutton">LinkButton
                        <asp:LinkButton ID="p1" runat="server" CssClass="Linkbutton">LinkButton
                        <asp:LinkButton ID="p2" runat="server" CssClass="Linkbutton">LinkButton
                        <asp:Label ID="CurrentPage" runat="server" Text="Label"  ForeColor ="#EEE000" Font-Size ="Medium" >
                        <asp:LinkButton ID="p4" runat="server" CssClass="Linkbutton">LinkButton
                        <asp:LinkButton ID="p5" runat="server" CssClass="Linkbutton">LinkButton
                        <asp:LinkButton ID="p6" runat="server" CssClass="Linkbutton">LinkButton
                        <asp:LinkButton ID="LinkButton3" runat="server" CommandName="Page" CommandArgument="Next" CssClass="Linkbutton">Next
                        <asp:Label ID="nmore" runat="server" Text="">
                        <asp:LinkButton ID="LinkButton4" runat="server" CommandName="Page" CommandArgument="Last" CssClass="Linkbutton">Last
                    </pagertemplate>
                    <%--<added by="" naresh=""></added>--%>
                
            </td>
        </tr>
        <asp:Label ID="lblresult" runat="server" Text="">
        <asp:Literal runat="server" ID="Literal1" />
    </table>
    <br />
    <hr />
    <table class="style1">
        <tr>
            <td class="style2"> </td>
            <td class="style2"><asp:Label ID="lblstr" runat ="server" Text ="*" Font-Bold ="true" Font-Size ="Large" ForeColor ="Blue">
            </td>
            <td class="style3">
                     <label style ="font-weight:bold;font-family:Times New Roman;font-size:small;">Product Description</label></td>
            <td>
                     = This is Used for Single Phase Meter 
            </td>
        </tr>
        <tr>
            <td class="style2">
                 
                    </td>
            <td class="style2">
                <asp:Label ID="Label2" runat ="server" Text ="*" Font-Bold ="true" Font-Size ="Large" ForeColor ="Blue" >
            </td>
            <td class="style3">
                      <label style ="font-weight:bold;font-family:Times New Roman;font-size:small;">In Stock</label></td>
            <td>
                     = Total Stock in Godown/Store Room (Ex:10,000)</td>
        </tr>
        <tr>
            <td class="style2">
                 </td>
            <td class="style2">
                <asp:Label ID="Label3" runat ="server" Text ="*" Font-Bold ="true" Font-Size ="Large" ForeColor ="Blue">
            </td>
            <td class="style3">
                    <label style ="font-weight:bold;font-family:Times New Roman;font-size:small;">Commited</label></td>
            <td>
                     = How Much Stock U have Dispatched (Ex:500) //Once check In Stock Quantity B4 Committed)</td>
        </tr>
        <tr>
            <td class="style2">
                 </td>
            <td class="style2">
                <asp:Label ID="Label4" runat ="server" Text ="*" Font-Bold ="true" Font-Size ="Large" ForeColor ="Blue">
            </td>
            <td class="style3">
                     <label style ="font-weight:bold;font-family:Times New Roman;font-size:small;">On Order</label></td>
            <td>
                     = PO of Order By Supplier/Vendor (Ex:1000)</td>
        </tr>
        <tr>
            <td class="style2">
                 </td>
            <td class="style2">
                <asp:Label ID="Label5" runat ="server" Text ="*" Font-Bold ="true" Font-Size ="Large" ForeColor ="Blue">
            </td>
            <td class="style3">
                      <label style ="font-weight:bold;font-family:Times New Roman;font-size:small;">WholeSale</label></td>
            <td>
                     = Total Price Of  each  OnOrder Product (Ex: Rs 27000.00)</td>
        </tr>
    </table>
    
  <code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Xml;

public partial class ProductGrid : System.Web.UI.Page
{
    static string PN;
    //ds is used Store Data And Bind to Grid
    static DataSet ds;
    // con is used for sqlConnection it get the Connection from connectionString class
    SqlConnection con = new SqlConnection(IMS.ConnectionString.getValue());
   protected void Page_Load(object sender, EventArgs e)
    {
        sessions.getsessions();  //by Shruthi
        SqlDataAdapter daAuth = new SqlDataAdapter("select ListOfProducts from submenu where user_type_id='" + Session["UTI"].ToString() + "'", con);
        DataSet dsAuth = new DataSet();
        daAuth.Fill(dsAuth, "Submenu");
        if (dsAuth.Tables["Submenu"].Rows[0]["ListOfProducts"].ToString() == "False")
        {
            Response.Redirect("default.aspx");
        }
        btn_delProduct.Enabled=btn_addProductDetails.Enabled=btnUpdate.Enabled=btn_show_ProductDetails.Enabled= false;
       btn_addNewProduct.Enabled = true;
        //HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        if (Page.IsPostBack == false)
        {
            getdata();
            IMSNiana.ProductName = "";
        }
              //}
    }

    
   public string getVal()
    {
        return PN;
    }
    public void getdata()
    {
        //da is fetch datafrom DataBase
        SqlDataAdapter da = new SqlDataAdapter("select * from product", con);
        ds = new DataSet();
        //it fill the dataset(ds)'s table with Product
        da.Fill(ds, "Product");
        //GVProduct.Dispose();
        GVProduct.DataSource = ds.Tables["Product"];
        GVProduct.DataBind();
    }

    public string getPName()
    {
        return IMSNiana.ProductName;
    }
    
    protected void GVProduct_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='orange'");
            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);
        }
    }
    protected void GVProduct_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)");
                    
        }
    }
    protected void chkselect_CheckedChanged(object sender, EventArgs e)
    {
        foreach (GridViewRow gvr in GVProduct.Rows)
        {
            CheckBox chk = (CheckBox)gvr.FindControl("chkselect");
            if (chk.Checked == true)
            {
                btn_addProductDetails.Enabled = btn_delProduct.Enabled = btnUpdate.Enabled =  btn_show_ProductDetails.Enabled = true;
                btn_addNewProduct.Enabled = false;
        
                Label pn = (Label)gvr.FindControl("productname");
                IMSNiana.ProductName = pn.Text;
               
                break;
            }
            else
            {
                btn_addProductDetails.Enabled = btn_delProduct.Enabled = btnUpdate.Enabled =btn_show_ProductDetails.Enabled= false;
                btn_addNewProduct.Enabled = true;
            }
        }
    }
   
    protected void GVProduct_DataBound(object sender, EventArgs e)
    {
        try  
        {
            GridViewRow gvrow = GVProduct.BottomPagerRow;
            Label lblcurrentpage = (Label)gvrow.Cells[0].FindControl("CurrentPage");
            lblcurrentpage.Text = Convert.ToString(GVProduct.PageIndex + 1);
            int[] page = new int[7];
            page[0] = GVProduct.PageIndex - 2;
            page[1] = GVProduct.PageIndex - 1;
            page[2] = GVProduct.PageIndex;
            page[3] = GVProduct.PageIndex + 1;
            page[4] = GVProduct.PageIndex + 2;
            page[5] = GVProduct.PageIndex + 3;
            page[6] = GVProduct.PageIndex + 4;
            for (int i = 0; i < 7; i++)
            {
                if (i != 3)
                {
                    if (page[i] < 1 || page[i] > GVProduct.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 (GVProduct.PageIndex == 0)
            {
                LinkButton lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("LinkButton1");
                lnkbtn.Visible = false;
                lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("LinkButton2");
                lnkbtn.Visible = false;
            }
            if (GVProduct.PageIndex == GVProduct.PageCount - 1)
            {
                LinkButton lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("LinkButton3");
                lnkbtn.Visible = false;
                lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("LinkButton4");
                lnkbtn.Visible = false;
            }
            if (GVProduct.PageIndex > GVProduct.PageCount - 5)
            {
                Label lbmore = (Label)gvrow.Cells[0].FindControl("nmore");
                lbmore.Visible = false;
            }
            if (GVProduct.PageIndex < 4)
            {
                Label lbmore = (Label)gvrow.Cells[0].FindControl("pmore");
                lbmore.Visible = false;
            }
        }
        catch
        {
        }
}
  public  void lb_Command(object sender, CommandEventArgs e)
   {
       GVProduct.PageIndex = Convert.ToInt32(e.CommandArgument) - 1;
       getdata();
    }

  protected void GVProduct_PageIndexChanging1(object sender, GridViewPageEventArgs e)
  {
      GVProduct.PageIndex = e.NewPageIndex;
      getdata();
  }
  protected void GVProduct_SelectedIndexChanged(object sender, EventArgs e)
  {
  }
  protected void btn_delProduct_Click1(object sender, EventArgs e)
  {
      SqlDataAdapter da = new SqlDataAdapter("select product_id from Product where product_name='" + IMSNiana.ProductName + "'", con);
      //ds is used store data fetched from Database
      DataSet ds = new DataSet();
      da.Fill(ds, "PN");
      string PId = ds.Tables["PN"].Rows[0][0].ToString();
      da = new SqlDataAdapter(" delete from ProductDetails where product_id='" + PId + "' delete from  Product where product_id='" + PId + "'", con);
      ds = new DataSet();
      da.Fill(ds, "Product");
      getdata();
     
  }
}

</code>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900