Add_view_category.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 Add_view_category : System.Web.UI.Page
{
BALCategoryMaster bal = new BALCategoryMaster();
DALCategoryMaster dal = new DALCategoryMaster();
DALProductMaster prodal = new DALProductMaster();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["id"] != null)
{
int CategoryId = int.Parse(Request.QueryString["id"].ToString());
bal.CategoryId = CategoryId;
DataTable dt = dal.select_CategoryMasterByCategoryId(bal);
if (dt.Rows.Count != 0)
{
txtcategory.Text = dt.Rows[0]["CategoryName"].ToString();
}
}
gvbind();
}
}
public void gvbind()
{
DataTable dt = dal.Select_CategoryMaster();
gvcategory.DataSource = dt;
gvcategory.DataBind();
ViewState["dtcat"] = dt;
}
protected void gvcategory_RowEditing(object sender, GridViewEditEventArgs e)
{
string categoryid = gvcategory.DataKeys[e.NewEditIndex].Value.ToString();
Response.Redirect("Add_view_category.aspx?id=" + categoryid);
}
protected void gvcategory_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int categoryid = int.Parse(gvcategory.DataKeys[e.RowIndex].Value.ToString());
bal.CategoryId = categoryid;
dal.delete_CategoryMaster(bal);
gvbind();
}
protected void gvcategory_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvcategory.PageIndex = e.NewPageIndex;
gvcategory.DataSource = (DataTable)ViewState["dtcat"];
gvcategory.DataBind();
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
if (Request.QueryString["id"] != null)
{
bal.CategoryName = txtcategory.Text.Trim().ToString().ToUpper();
bal.CategoryId = int.Parse(Request.QueryString["id"].ToString());
dal.update_CategoryMaster(bal);
Response.Redirect("Add_view_category.aspx");
}
else
{
bal.CategoryName = txtcategory.Text.Trim().ToString().ToUpper();
dal.insert_CategoryMaster(bal);
Response.Redirect("Add_view_category.aspx");
}
}
protected void Submit_Click(object sender, EventArgs e)
{
string search = txtsearch.Text.ToString();
DataTable dt = dal.Select_CategoryMasterSearch(search);
gvcategory.DataSource = dt;
gvcategory.DataBind();
ViewState["dtcat"] = dt;
}
}
Add_view_category.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="Add_view_category.aspx.cs" Inherits="Add_view_category" 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">
CREATE CATEGORY
</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 width="520" align="left" valign="top">
<table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="225" align="left" valign="middle" class="fields">
CATEGORY NAME:
</td>
<td width="147" align="left" valign="middle">
<asp:TextBox ID="txtcategory" runat="server" Width="147" class="fields"></asp:TextBox>
</td>
<td width="142">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtcategory"
ErrorMessage="*" ValidationGroup="ok"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td width="225" align="left" valign="middle" class="fields">
</td>
<td width="147" align="left" valign="middle">
</td>
<td width="142">
</td>
</tr>
<tr>
<td height="15" colspan="3" align="left" valign="middle" class="fields">
</td>
</tr>
<tr>
<td colspan="3" align="center" valign="middle">
<table width="82%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="middle">
</td>
<td width="60">
<asp:Button ID="btnsubmit" runat="server" Text="Submit" OnClick="btnsubmit_Click" />
</td>
<td align="right" valign="middle">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="60" colspan="3" align="left" valign="middle">
</td>
</tr>
<tr>
<td align="left" valign="middle">
</td>
<td>
</td>
<td align="left" valign="middle">
<a style="border: none;" class="thickbox"> </a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="535">
<tr>
<td height="10">
<asp:TextBox ID="txtsearch" runat="server"></asp:TextBox>
<asp:Button ID="Submit" runat="server" Text="Button" />
</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: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">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" colspan="3" height="60" valign="middle">
</td>
</tr>
<tr>
<td align="left" valign="middle">
</td>
<td>
</td>
<td align="left" valign="middle">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td align="left" valign="top">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" valign="top">
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Content>