HI EVERY ONE,
I palce a delete button bellow the gv. if user checks on checkbox then that row will become updatable format. Now i want to update those details in the database. plz help me soon. if any one doesn't understand the prob plz ask me again. i will explain in details.
Loading
Kirtan PatelPosted Feb 6, 2010, 3:07 AM
Here is Sample Code i have Coded for you !!
just Take a Look at Attachment I have attached Example Project Files
protected void Page_Load(object sender, EventArgs e)
{
// Load the Data
if (!IsPostBack)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand comm = new SqlCommand("select * from UserData", con);
GridView1.DataSource = comm.ExecuteReader();
DataBind();
con.Close();
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
foreach (GridViewRow r in GridView1.Rows)
{
if (((CheckBox)r.Cells[0].FindControl("CheckBox1")).Checked == true)
{
//Take Key Value From Row And Delete it From Database
string username = r.Cells[1].Text;
//Delete it
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand comm = new SqlCommand("delete from userdata where username='"+username+"'", con);
comm.ExecuteNonQuery();
con.Close();
}
}
Response.Redirect("Default.aspx");
}
Lalit MPosted Feb 6, 2010, 2:13 AM
http://aspalliance.com/1125_Dynamically_Templated_GridView_with_Edit_Delete_and_Insert_Options.all
Thanks hemanth hemanth....