protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { FillLga(); } } protected void ddlLga_SelectedIndexChanged(object sender, EventArgs e) { int lga_id = Convert.ToInt32(ddlLga.SelectedValue.ToString()); FillWards(lga_id); ddlPu.SelectedIndex = 0; } protected void ddlWard_SelectedIndexChanged(object sender, EventArgs e) { int ward_id = Convert.ToInt32(ddlWard.SelectedValue.ToString()); FillPu(ward_id); }
private void FillLga() { string strConn = ConfigurationManager.ConnectionStrings["con"].ConnectionString; SqlConnection con = new SqlConnection(strConn); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT lga_id, lga_name FROM lga_tbl"; DataSet objDs = new DataSet(); SqlDataAdapter dAdapter = new SqlDataAdapter(); dAdapter.SelectCommand = cmd; con.Open(); dAdapter.Fill(objDs); con.Close(); if (objDs.Tables[0].Rows.Count > 0) { ddlLga.DataSource = objDs.Tables[0]; ddlLga.DataTextField = "lga_name"; ddlLga.DataValueField = "lga_id"; ddlLga.DataBind(); ddlLga.Items.Insert(0, "--Select--"); } else { lblMsg.Text = "No Local Government Found"; } }
private void FillWards(int lga_id) { string strConn = ConfigurationManager.ConnectionStrings["con"].ConnectionString; SqlConnection con = new SqlConnection(strConn); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT ward_id, ward_name FROM ward_tbl WHERE lga_id ='" + ddlLga.SelectedValue + "'"; cmd.Parameters.AddWithValue("@lga_id", lga_id); DataSet objDs = new DataSet(); SqlDataAdapter dAdapter = new SqlDataAdapter(); dAdapter.SelectCommand = cmd; con.Open(); dAdapter.Fill(objDs); con.Close(); if (objDs.Tables[0].Rows.Count > 0) { ddlWard.DataSource = objDs.Tables[0]; ddlWard.DataTextField = "ward_name"; ddlWard.DataValueField = "ward_id"; ddlWard.DataBind(); ddlWard.Items.Insert(0, "--Select--"); } else { lblMsg.Text = "No Ward found"; } }
private void FillPu(int ward_id) { string strConn = ConfigurationManager.ConnectionStrings["con"].ConnectionString; SqlConnection con = new SqlConnection(strConn); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT pu_id, pu_name FROM pu_tbl WHERE ward_id ='" + ddlWard.SelectedValue + "'"; cmd.Parameters.AddWithValue("@ward_id", ward_id); DataSet objDs = new DataSet(); SqlDataAdapter dAdapter = new SqlDataAdapter(); dAdapter.SelectCommand = cmd; con.Open(); dAdapter.Fill(objDs); con.Close(); if (objDs.Tables[0].Rows.Count > 0) { ddlPu.DataSource = objDs.Tables[0]; ddlPu.DataTextField = "pu_name"; ddlPu.DataValueField = "pu_id"; ddlPu.DataBind(); ddlPu.Items.Insert(0, "--Select--"); } else { lblMsg.Text = "No Cities found"; } }
// Registration button click event protected void Button1_Click(object sender, EventArgs e) { String p = UniqueNumber();
SqlConnection con = new SqlConnection(strcon); con.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO members_master_tbl (full_name,dob,gender,phone,lga,ward,pu,pvc,status,refnumber) values(@full_name,@dob,@gender,@phone,@lga,@ward,@pu,@pvc,@status,@refnumber)", con); cmd.Parameters.AddWithValue("@full_name", TextBox1.Text.Trim()); cmd.Parameters.AddWithValue("@dob", TextBox2.Text.Trim()); cmd.Parameters.AddWithValue("@gender", DropDownList2.SelectedItem.Value); cmd.Parameters.AddWithValue("@phone", TextBox3.Text.Trim()); cmd.Parameters.AddWithValue("@lga", ddlLga.SelectedItem.Value); cmd.Parameters.AddWithValue("@ward", ddlWard.SelectedItem.Value); cmd.Parameters.AddWithValue("@pu", ddlPu.SelectedItem.Value); cmd.Parameters.AddWithValue("@pvc", TextBox6.Text.Trim()); cmd.Parameters.AddWithValue("@status", "Pending"); cmd.Parameters.AddWithValue("@refnumber", Label2.Text.Trim()); cmd.ExecuteNonQuery(); con.Close();
Session["id"] = Label2.Text; Session["full_name"] = TextBox1.Text; Session["dob"] = TextBox2.Text; Session["gender"] = DropDownList2.SelectedItem.Value; Session["lga"] = ddlLga.SelectedItem.Value; Session["ward"] = ddlWard.SelectedItem.Value; Session["pu"] = ddlPu.SelectedItem.Value; Session["status"] = "Pending";
//Response.Write("<script>alert('Testing');</script>"); try { Response.Redirect("~/refnumber.aspx"); } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }
// user defined method
Attachment: Source.rar