Anda di halaman 1dari 4

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;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings
["info1"].ConnectionString);
int count;
public static SqlConnection sql = new SqlConnection(ConfigurationManager.Con
nectionStrings["info1"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter adp = new SqlDataAdapter("select* From info1", con);
DataSet ds = new DataSet();
adp.Fill(ds);
//GridView2.DataSource = ds.Tables[0];
GridView2.DataBind();
con.Close();
if (Page.IsPostBack == false)
{
ddl_state.Enabled = false;
ddl_city.Enabled = false;
country();
}
}
protected void ddl_country_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
sql.Open();
ddl_state.Enabled = true;
SqlCommand com1 = new SqlCommand("select sname from statedetail wher
e cid in(select cid from countrydetails where cmane='" + ddl_country.SelectedVal
ue.ToString() + "')", sql);
com1.ExecuteNonQuery();
SqlDataAdapter da1 = new SqlDataAdapter(com1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);

ddl_state.DataTextField = "sname";
ddl_state.DataBind();
sql.Close();
ddl_state.Items.Clear();
ddl_state.Items.Add("----select-------");

for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
ddl_state.Items.Add(ds1.Tables[0].Rows[i].ItemArray.GetValue(0).
ToString());
}
}
catch { }
finally
{
sql.Close();
}
}
protected void ddl_state_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
ddl_city.Items.Clear();
ddl_city.Enabled = true;
sql.Open();
SqlCommand com2 = new SqlCommand("select pname from placedetail wher
e sid in(select sid from statedetail2 where sname='" + ddl_state.SelectedItem.To
String() + "')", sql);
com2.ExecuteNonQuery();
SqlDataAdapter dr2 = new SqlDataAdapter(com2);
DataSet ds2 = new DataSet();
dr2.Fill(ds2);
ddl_city.DataTextField = "pname";
ddl_city.DataBind();
sql.Close();
ddl_city.Items.Clear();
ddl_city.Items.Add("------select-------");
for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
{
ddl_city.Items.Add(ds2.Tables[0].Rows[i].ItemArray.GetValue(0).T
oString());
}
}
catch { }
finally
{
sql.Close();
}
}
public void country()
{
sql.Close();
sql.Open();
ddl_country.Items.Clear();
SqlCommand com = new SqlCommand("select cmane from countrydetails", sql)
;
com.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds);
sql.Close();
ddl_country.Items.Add("----select-------");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ddl_country.Items.Add(ds.Tables[0].Rows[i].ItemArray.GetValue(0).ToS
tring());
}
}
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from info1", con);
count = (int)cmd.ExecuteScalar();
count += 1;
string str = "ID" + count;
txtid.Text = str;
txt1.Text = "";
deg_dd2.ClearSelection();
ddl_country.ClearSelection();
ddl_city.ClearSelection();
ddl_state.ClearSelection();
ddl_state.Enabled = false;
ddl_city.Enabled = false;
}
protected void Button2_Click(object sender, EventArgs e)
{
con.Open();
string gen;
if (rbt1.Checked == true && rbt2.Checked == false)
{
gen = rbt1.Text;
}
else
{
gen = rbt2.Text;
}
SqlCommand com = new SqlCommand("insert into info1 values('" + txtid.Tex
t.ToString() + "','" + txt1.Text.ToString() + "','" + gen.ToString() + "','" + d
eg_dd2.SelectedItem.Text + "','" + ddl_country.SelectedItem.Text + "','" + ddl_s
tate.SelectedItem.Text + "','" + ddl_city.SelectedItem.Text + "')", con);
com.ExecuteNonQuery();
con.Close();
}
protected void Button3_Click(object sender, EventArgs e)
{
string gen;
if (rbt1.Checked == true && rbt2.Checked == false)
{
gen = rbt1.Text;
}
else
{
gen = rbt2.Text;
}
con.Open();
SqlDataAdapter adp = new SqlDataAdapter("update info1 SET name='" + txt1
.Text + "', gender='" + gen + "',degree='" + deg_dd2.SelectedItem.Text + "',coun
try='" + ddl_country.SelectedItem.Text + "',state='" + ddl_state.SelectedItem.Te
xt + "',city='" + ddl_city.SelectedItem.Text + "' Where id='" + txtid.Text + "'"
, con);
DataSet ds = new DataSet();
adp.Fill(ds);
//GridView2.DataSource = ds.Tables[0];
GridView2.DataBind();
con.Close();
}

}