problem when deleting rows in gridview in update panel
hi all i have gridview and iwant to delete rows,
the gridview in update panel.
i take the code from
http://www.aspsnippets.com/post/2009/10/17/Select-and-delete-multiple-rows-in-ASPNet-Gridview-control.aspx
and its work without update panel, but when i want to use it in update panel the updatepanel refreshed without deleting any rows
can any one help me?
Kirtan PatelPosted Dec 11, 2009, 2:58 PM
Here I coded the Sample For you Just Take a Look
Download My Project Files to take Reference :)
Check "do you like this answer" check box if it helps you :)
Code
-------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowDataInGrid();
}
}
public void ShowDataInGrid()
{
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 Users", con);
GridView1.DataSource = comm.ExecuteReader();
DataBind();
con.Close();
}
protected void btnDeleteChecked_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
con.Open();
foreach (GridViewRow r in GridView1.Rows)
{
if (((CheckBox)r.FindControl("CheckBox1")).Checked == true)
{
string UserName = r.Cells[1].Text;
SqlCommand comm = new SqlCommand("DELETE FROM Users where username=@username", con);
comm.Parameters.AddWithValue("@username", UserName);
comm.ExecuteNonQuery();
ShowDataInGrid();
}
}
}
Kirtan PatelPosted Dec 12, 2009, 2:02 PM
I am fine .
ask question when ever you need helps :)
abas shahenPosted Dec 11, 2009, 10:30 PM