You are on page 1of 4

using System;

using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class AdminZone_AEState : System.Web.UI.Page
{
public static string conStr = "Data Source=LAB1-39;Initial Catalog=NetBankin
g;Integrated Security=True";
public static SqlConnection conn;
public static SqlCommand cmd;
public static SqlDataAdapter da;
public static SqlDataReader dr;
public static DataSet ds;
public static DataTable dt;
public int ids;
protected void Page_Load(object sender, EventArgs e)
{
try
{
txtID.Visible = false;
txtID.Text = Request["sid"];
if (!IsPostBack)
{
if (txtID.Text != "")
{
DataSet dt = new DataSet();
conn = new SqlConnection(conStr);
string str = "select * from tblStateMaster where StateId='"+
txtID.Text +"'";
da = new SqlDataAdapter(str, conn);
da.Fill(dt);
if (dt.Tables[0].Rows.Count > 0)
{
txtStateName.Text = dt.Tables[0].Rows[0]["StateName"].To
String();
txtStateCode.Text = dt.Tables[0].Rows[0]["StateCode"].To
String();
btnSave.Enabled = true;
btnSave.Text = "Update";
}
else
{
Response.Write("Errorr...");
}
txtID.Visible = true;
txtID.Text = "" + Session["ids"];
Response.Write(ids);
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
if (btnSave.Text == "Save")
{
string qStr = "insert into tblStateMaster(StateName,StateCode)values
('" + txtStateName.Text + "','" + txtStateCode.Text + "')";
conn = new SqlConnection(conStr);
cmd = new SqlCommand(qStr, conn);
try
{
conn.Open();
cmd.Connection = conn;
cmd.ExecuteNonQuery();
conn.Close();
lblError.Text = "Data is Saved Successfully..";
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
}
else if (btnSave.Text == "Update")
{
string qUpdate = "update tblStateMaster set StateName='" + txtStateN
ame.Text + "',StateCode='"+ txtStateCode.Text +"' where StateId='"+ txtID.Text +
"'";
conn = new SqlConnection(conStr);
cmd = new SqlCommand(qUpdate, conn);
try
{
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
lblError.Text = "Data is Updated Successfully..";
btnSave.Text = "Save";
txtStateName.Text = "";
txtStateCode.Text = "";
txtStateName.Focus();
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
}
}
public void FillText()
{
conn = new SqlConnection(conStr);
string qStr = "select * from tblStateMaster where StateId='"+ Session["i
ds"].ToString() +"'";
cmd = new SqlCommand(qStr, conn);
dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
txtStateName.Text = dt.Rows[0]["StateId"].ToString();
txtStateCode.Text = dt.Rows[0]["StateCode"].ToString();
//txtr.Text = dt.Rows[0]["StateId"].ToString();
}
}
}

*-*-*-*-*-*-*-*-*
<%@ Page Language="C#" MasterPageFile="~/AdminZone/AdminMasterPage.master" AutoE
ventWireup="true"
CodeFile="AEState.aspx.cs" Inherits="AdminZone_AEState" Title="::Add New Sta
te ::" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutr
al, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Ser
ver">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0><TBODY><TR><TD vAlign=t
op align=right><IMG src="Images/inner-left.gif" /></TD><TD class="inneractive" v
Align=middle align=left width="100%" bgColor=#9eafc1><STRONG>Add/Edit State</STR
ONG></TD><TD vAlign=top align=left><IMG src="Images/inner-right.gif" /></TD></TR
></TBODY></TABLE><TABLE style="FONT-SIZE: 12px" cellPadding=3 width="95%" align=
center border=0><TBODY><TR><TD style="HEIGHT: 21px" align=center colSpan=2><asp:
Label id="lblError" runat="server" ForeColor="Red">&nbsp;</asp:Label></TD></TR><
TR><TD class="txthead" vAlign=top noWrap align=right width="15%"><asp:Label styl
e="POSITION: static" id="lblStateId" runat="server" Font-Bold="True" Width="47px
" __designer:wfdid="w18" Visible="False"></asp:Label></TD><TD class="txthead" vA
lign=top noWrap><asp:TextBox style="POSITION: static" id="txtID" runat="server"
Visible="False" Columns="2"></asp:TextBox></TD></TR><TR><TD class="txthead" vAli
gn=top noWrap align=right width="15%"><STRONG>State Name::</STRONG></TD><TD clas
s="txthead" vAlign=top noWrap><asp:TextBox id="txtStateName" runat="server" Colu
mns="30" MaxLength="50" CssClass="input"></asp:TextBox> *<asp:RequiredFieldValid
ator id="Requiredfieldvalidator2" runat="server" Display="Dynamic" ErrorMessage=
"State Name is required" ControlToValidate="txtStateName">State Name is required
</asp:RequiredFieldValidator></TD></TR><TR><TD style="HEIGHT: 19px" class="txthe
ad" vAlign=top noWrap align=right><STRONG>State Code::</STRONG></TD><TD style="H
EIGHT: 19px" class="txthead" vAlign=top noWrap><asp:TextBox id="txtStateCode" ru
nat="server" Columns="30" MaxLength="50" CssClass="input"></asp:TextBox> *<asp:R
equiredFieldValidator id="Requiredfieldvalidator3" runat="server" Display="Dynam
ic" ErrorMessage="State Code is required" ControlToValidate="txtStateCode">State
Code is required</asp:RequiredFieldValidator></TD></TR><TR><TD style="HEIGHT: 1
9px" vAlign=top></TD><TD style="HEIGHT: 19px" vAlign=top><asp:Button style="POSI
TION: static" id="btnSave" onclick="btnSave_Click" runat="server" Font-Size="11p
x" Font-Bold="True" Width="60px" Text="Save" Height="22px" __designer:wfdid="w9"
BackColor="#FFC080" BorderColor="#FF8080" BorderStyle="Groove"></asp:Button> <a
sp:Button style="POSITION: static" id="btnCance" runat="server" Font-Size="11px"
Font-Bold="True" Text="Cancel" Height="22px" __designer:wfdid="w10" BackColor="
#FFC080" BorderColor="#FF8080" BorderStyle="Groove" PostBackUrl="~/AdminZone/Sta
teList.aspx"></asp:Button></TD></TR></TBODY></TABLE>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>