using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; public partial class Agent_UserReg : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { txtFirst.Focus(); getAgentID(); } } private void getAgentID() { AgentBAL bo = new AgentBAL(); DataSet ds = new DataSet(); ds = bo.GetAgentID(); DropDownList1.DataSource = ds; DropDownList1.DataTextField = "AgentID"; DropDownList1.DataValueField = "AgentID"; DropDownList1.DataBind(); DropDownList1.Items.Insert(0, "--Select--"); } protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString()); //SqlConnection con = new SqlConnection("Data Source=VICTORY2;database=Binary;User ID=sa;Password=p@ssword"); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; cmd.Connection = con; con.Open(); cmd.CommandText = "insert into Registration(CenterID,FirstName,LastName,UserName,Password,EmailID,PhoneNo,Address,Role) values('" + DropDownList1.SelectedItem.Text + "','" + txtFirst.Text + "','" + txtLast.Text + "','" + txtUserName.Text + "','" + txtPwd.Text + "','" + txtEmail.Text + "','" + txtPhn.Text + "','" + txtAddrss.Text + "','" + txtrole.Text + "')"; int i = cmd.ExecuteNonQuery(); if (i > 0) { lblmess.Visible = true; lblmess.Text = "Success"; } else { lblmess.Visible = true; lblmess.Text = "Enter Valid Details"; } con.Close(); } protected void Button2_Click(object sender, EventArgs e) { Clear(); } private void Clear() { foreach (Control ctrl in ((ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1")).Controls) { if (ctrl.GetType() == typeof(TextBox)) { ((TextBox)ctrl).Text = string.Empty; } if (ctrl.GetType() == typeof(DropDownList)) { ((DropDownList)ctrl).SelectedIndex = 0; } } } }