Sunday, April 1, 2012

Product Catelog App class in asp.net c# -7


view_product.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="view_product.aspx.cs" Inherits="view_product" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <table>
        <tr>
            <td width="63%" align="right" valign="top">
                <table width="90%" border="0" align="right" cellpadding="0" cellspacing="0" style="padding: 40px 0 0 0;
                    margin-top: 10px;">
                    <tr>
                        <td width="90%" align="right" valign="top">
                            <table width="90%" border="0" align="right" cellpadding="0" cellspacing="0" style="margin-bottom: 25px;">
                                <tr>
                                    <td align="left">
                                        <table width="98%" align="left" cellpadding="0" cellspacing="0" style="margin: 25px 0 0 0;">
                                            <tr>
                                                <td align="left" valign="top" class="style13">
                                                    VIEW PRODUCT
                                                </td>
                                                <td width="198" height="35" align="right" valign="middle" class="style4">
                                                </td>
                                            </tr>
                                            </TBODY>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left">
                                        <table width="535" border="0" align="center" cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td height="10">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <table align="center" border="0" cellpadding="0" cellspacing="0" width="535">
                                                        <tr>
                                                            <td height="10">
                                                                <table style="width: 100%">
                                                                    <tr>
                                                                        <td align="left" style="width: 50%">
                                                                            <asp:TextBox ID="txtsearch" Text="Search by ProductName" runat="server" OnClick="this.value = ''; this.style.color = 'black'" OnBlur="javascript:changeText(this.id)"></asp:TextBox>
                                                                            <asp:Button ID="Submit" runat="server" Text="Button" OnClick="Submit_Click" />
                                                                        </td>
                                                                        <td align="right" style="width: 50%">
                                                                            <asp:DropDownList ID="drpcategory" runat="server" OnSelectedIndexChanged="drpcategory_SelectedIndexChanged">
                                                                            </asp:DropDownList>
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td align="left" valign="top" width="520">
                                                                <table border="0" cellpadding="0" cellspacing="0" width="90%">
                                                                    <tr>
                                                                        <td align="center" colspan="3" height="15" valign="middle">
                                                                            <h1>
                                                                                <asp:GridView ID="gvcategory" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                                                                                    CellPadding="5" DataKeyNames="CategoryId" OnPageIndexChanging="gvcategory_PageIndexChanging"
                                                                                    OnRowDeleting="gvcategory_RowDeleting" OnRowEditing="gvcategory_RowEditing" Width="80%">
                                                                                    <HeaderStyle CssClass="Head" />
                                                                                    <RowStyle CssClass="rowtext" />
                                                                                    <Columns>
                                                                                        <asp:TemplateField HeaderText="ID" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="7%">
                                                                                            <ItemTemplate>
                                                                                                <%#Container.DataItemIndex+1 %>
                                                                                            </ItemTemplate>
                                                                                            <ItemStyle HorizontalAlign="Center" Width="7%" />
                                                                                        </asp:TemplateField>
                                                                                        <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" ItemStyle-HorizontalAlign="Left">
                                                                                            <ItemStyle HorizontalAlign="Left" />
                                                                                        </asp:BoundField>
                                                                                        <asp:BoundField DataField="productname" HeaderText="ProductName" ItemStyle-HorizontalAlign="Left">
                                                                                            <ItemStyle HorizontalAlign="Left" />
                                                                                        </asp:BoundField>
                                                                                        <asp:BoundField DataField="productcode" HeaderText="ProductCode" ItemStyle-HorizontalAlign="Left">
                                                                                            <ItemStyle HorizontalAlign="Left" />
                                                                                        </asp:BoundField>
                                                                                        <asp:TemplateField HeaderText="ProductImage">
                                                                                            <ItemTemplate>
                                                                                                <img src="CreateThumbnail.aspx?image=upload/product/<%# Eval("image") %>&width=50" />
                                                                                            </ItemTemplate>
                                                                                        </asp:TemplateField>
                                                                                        <asp:CommandField ControlStyle-CssClass="link" ItemStyle-HorizontalAlign="Center"
                                                                                            ShowEditButton="True">
                                                                                            <ControlStyle CssClass="link" />
                                                                                            <ItemStyle HorizontalAlign="Center" />
                                                                                        </asp:CommandField>
                                                                                        <asp:CommandField ControlStyle-CssClass="link" ItemStyle-HorizontalAlign="Center"
                                                                                            ShowDeleteButton="True">
                                                                                            <ControlStyle CssClass="link" />
                                                                                            <ItemStyle HorizontalAlign="Center" />
                                                                                        </asp:CommandField>
                                                                                    </Columns>
                                                                                </asp:GridView>
                                                                            </h1>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td align="center" colspan="3" valign="middle">
                                                                            <table border="0" cellpadding="0" cellspacing="0" width="82%">
                                                                                <tr>
                                                                                    <td width="60">
                                                                                        &nbsp;
                                                                                    </td>
                                                                                </tr>
                                                                            </table>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td align="left" colspan="3" height="60" valign="middle">
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td align="left" valign="middle">
                                                                            &nbsp;
                                                                        </td>
                                                                        <td>
                                                                            &nbsp;
                                                                        </td>
                                                                        <td align="left" valign="middle">
                                                                            <a class="thickbox" style="border: none;">&nbsp;</a>
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                &nbsp;
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td align="left" valign="top">
                                                                &nbsp;
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="left" valign="top">
                                                    &nbsp;
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</asp:Content>







view_product.aspx.cs



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class view_product : System.Web.UI.Page
{
    BALProductMaster bal = new BALProductMaster();
    DALProductMaster dal = new DALProductMaster();
    BALCategoryMaster catbal = new BALCategoryMaster();
    DALCategoryMaster catdal = new DALCategoryMaster();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            drpcategory.DataSource = catdal.SelectCategory();
            drpcategory.DataBind();
            drpcategory.SelectedItem.Text = "category";
            drpcategory.SelectedValue = "id";
            gvbind();
        }
    }
    public void gvbind()
    {
        DataTable dt = dal.Select_ProductMaster();
        gvcategory.DataSource = dt;
        gvcategory.DataBind();
        ViewState["dtpro"] = dt;
    }
    protected void gvcategory_RowEditing(object sender, GridViewEditEventArgs e)
    {
        string productid = gvcategory.DataKeys[e.NewEditIndex].Value.ToString();
        Response.Redirect("Add_product.aspx?id=" + productid);
    }
    protected void gvcategory_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int productid = int.Parse(gvcategory.DataKeys[e.RowIndex].Value.ToString());
        bal.ProductID = productid;
        dal.delete_ProductMaster(bal);
        gvbind();
    }
    protected void gvcategory_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvcategory.PageIndex = e.NewPageIndex;
        gvcategory.DataSource = (DataTable)ViewState["dtpro"];
        gvcategory.DataBind();
    }
    protected void drpcategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        catbal.CategoryId = int.Parse(drpcategory.SelectedValue.ToString());
        DataTable dt = dal.selectR_ProductMasterByCategoryId(catbal);
        gvcategory.DataSource = dt;
        gvcategory.DataBind();
        ViewState["dtpro"] = dt;
    }
    protected void Submit_Click(object sender, EventArgs e)
    {
        string search = txtsearch.Text.ToString();
        DataTable dt = dal.Select_ProductMasterSearch(search);
        gvcategory.DataSource = dt;
        gvcategory.DataBind();
        ViewState["dtcat"] = dt;
    }
}