for deleting data in gridview it deletes the entire row?

Posted by Sudheep.grandhe under C# on 12/14/2011 | Points: 10 | Views : 1686 | Status : [Member] | Replies : 9
Hi,

i want to delete the data in gridview.i wrote the code for that but it will delete the entire data.if i selected one row it will delete the entire row.

private void btn_delete_Click(object sender, EventArgs e)
{
if (this.GridView1.SelectedRows.Count > 0)
{
GridView1.Rows.RemoveAt(this.GridView1.SelectedRows[0].Index);
}
}

Best,
Sudheep.



Responses

Posted by: Hmanjarawala on: 12/14/2011 [Member] Bronze | Points: 25

Up
0
Down
what is expected behaviour??

delete full row or specific cell data???

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 12/14/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,
i want both scenarios.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 12/14/2011 [Member] Bronze | Points: 25

Up
0
Down
your code is correct for delete entire row
but if you want to delete perticular cell data do one thing 1st

set
gridview1.AllowUserToDeleteRow = false;


and then go to perticular cell and press Escape ("Esc") key


Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 12/14/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

as you said i will fix the properties of a gridview as false . but,when i want to delete paricular cell and i press " esc".the entire form also closing.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 12/14/2011 [Member] Bronze | Points: 25

Up
0
Down
have you code that thing on pressing Esc Key???

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 12/14/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

where i have to write the code for pressing esc key .i set the gridview properties window as false.i didn't write code for that.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 12/14/2011 [Member] Bronze | Points: 25

Up
0
Down
write code on cellBeginEdit event of gridview

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 12/15/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

what code i have to write in this cellbeginedit event.please do the needful

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 12/15/2011 [Member] Bronze | Points: 25

Up
0
Down
i dont have exact code....

but just check that if Keys.KeyCode == KeyCode.Escape then gridview.CurrentCell.Value=""

plz do it according to syntax

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response