Hello guys, I was wondering how do I delete a particulat record from a data grid. In other words I'm displaying bunch of messages to teh user and then there is going to be a button that will allow us to delete the message that is selected (by the way, Data grid has a check box colum which needs to be checked and the checked message would be deleted). Now I know that in 2.0, the Grid view has built in supprot for updates and deletes, but this button (DELETE) needs to just show up at the top just once in the header and not next to every single row in the data grid...could some one tell me how do I go through each row in grid view, and based on what's checked, delete that record from the Data base.
Thanks
Loading
Munir ShaikhPosted Jul 30, 2007, 3:34 AM
Here is full code which you can have a look, in this i am just getting values of check boxes in the gridview on signle button click, which in your case will act as 'Delete' button. you can fire delete statement once you get checkbox id's very easily.
Here is my aspx page
http://www.w3.org/1999/xhtml" >
Here is my Codebehind Page
protected void btnValue_Click(object sender, EventArgs e)
{
StringBuilder str = new StringBuilder();
// Select the checkboxes from the GridView control
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;
if (isChecked)
{
// Column 2 is the name column
str.Append(GridView1.Rows[i].Cells[1].Text);
}
}
Response.Write(str.ToString());
}