public partial class _Default : System.Web.UI.Page
{
string str = System.Configuration.ConfigurationManager.ConnectionStrings["_constr"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("select * from Registration_Simple",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
public void getDataset(string sql, DataSet ds)
{
SqlConnection con = new SqlConnection(str);
SqlDataAdapter da = new SqlDataAdapter();
con.Open();
da = new SqlDataAdapter(sql, con);
da.Fill(ds);
con.Close();
}
public void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
SqlConnection con = new SqlConnection(str);
try
{
if (e.CommandName == "update")
{
LinkButton linbtnupdate = (LinkButton)e.CommandSource;
int index = Convert.ToInt32(linbtnupdate.CommandArgument);
String ID1 = ((HiddenField)GridView1.Rows[index].FindControl("HiddenField1")).Value;
int a = int.Parse(ID1);
ViewState["HiddenID"] = a;
DataSet ds = new DataSet();
con.Open();
string sqlquery = "select Name, Gender, Address, State, city, Zipcode,Username from Registration_Simple where id=" + ID1;
getDataset(sqlquery,ds);
string Name = ds.Tables[0].Rows[0]["Name"].ToString();
string Gender = ds.Tables[0].Rows[0]["Gender"].ToString();
string Address = ds.Tables[0].Rows[0]["Address"].ToString();
string State = ds.Tables[0].Rows[0]["State"].ToString();
string city = ds.Tables[0].Rows[0]["city"].ToString();
string Zipcode = ds.Tables[0].Rows[0]["Zipcode"].ToString();
string Username = ds.Tables[0].Rows[0]["Username"].ToString();
TxtName.Text = Name;
Txt_Gender.Text = Gender;
txtAddress.Text = Address;
TxtState.Text = State;
Txtcity.Text = city;
TxtZipcode.Text = Zipcode;
Txt_Username.Text = Username;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
}
protected void Bttn_CLEAR_Click(object sender, EventArgs e)
{
TxtName.Text = null;
Txt_Gender.Text = null;
txtAddress.Text = null;
TxtState.Text = null;
Txtcity.Text = null;
TxtZipcode.Text = null;
Txt_Username.Text = null;
}
protected void bttn_Register_Click(object sender, EventArgs e)
{
Response.Redirect("Registration.aspx");
}
public void bttn_Update_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("sp_Update_Registration_Simple", con);
try
{
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_Update_Registration_Simple";
cmd.Parameters.AddWithValue("@id", ViewState["HiddenID"]);
cmd.Parameters.AddWithValue("@Name", TxtName.Text);
cmd.Parameters.AddWithValue("@Gender", Txt_Gender.Text);
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@State", TxtState.Text);
cmd.Parameters.AddWithValue("@City", Txtcity.Text);
cmd.Parameters.AddWithValue("@Zipcode", TxtZipcode.Text);
cmd.Parameters.AddWithValue("@USERNAME", Txt_Username.Text);
cmd.ExecuteNonQuery();
Response.Write("DATA UPDATED");
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
}