I am using a simple gridview which is as following:
<asp:GridView ID="grdViewData" runat="server" Width="98%" DataKeyNames="RecordID" OnSelectedIndexChanged="grdViewData_SelectedIndexChanged"
onrowcommand="grdViewData_RowCommand">
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server"
CausesValidation="False" CommandName="Select" OnClientClick="window.scroll(0,0)"
Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lnkDelete" runat="server"
CausesValidation="False" CommandName="Delete"
OnClientClick="return confirm('Do you want to delete this record?');" Text="Delete" CommandArgument="<%# Container.DataItemIndex %>"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns> </asp:GridView>
For updating the records in gridview i use gridview_SelectedIndexChanged method where as for deleting records i use gridview_RowCommand (if e.CommandName == "Delete") method as follows:
protected void grdViewData_SelectedIndexChanged(object sender, EventArgs e)
{
// Code Working properly Controls on page also getting updated
}
protected void grdViewData_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
// Code to Delete Record (Working Properly, Record being deleted.)
// Here Onwards code not working
Message.Text = "Data Deleted Successfully..";
ErrorMessage.Text = "";
}
}
In case of updating records, After updating I have some code to update controls on page which is working properly, but In case of deleting records, Records are being deleted but controls on page do not get updated. Attaching debugger shows that the code is executed perfectly but yet yet controls are not updated.
I have been googling for a day and really need to know the reason instead of going for alternative.
Related
How to make all the row cells editable on click of the edit button.
Following is the code snipped. Any help would be appreciated. On click of btnEdit_Click event, i want the radgrid row cells editable so that use can update existing data. i dont want to add inline edit button for each row in radgrid, instead on single edit button, all row cells should be editable based on their data type.
<asp:ImageButton runat="server" ID="btnEdit" ImageUrl="~/images/Buttons/Edit.gif"
OnClick="btnEdit_Click" />
<radG:RadGrid ID="grdAction" runat="server" AllowPaging="True" Width="100%" EnableAJAXLoadingTemplate="true"
CellPadding="1" CellSpacing="1" AllowSorting="True" ShowHeader="false" OnNeedDataSource="grd_View_NeedDataSource"
OnDetailTableDataBind="grd_View_DetailTableDataBind" PageSize="11" MasterTableView-GroupsDefaultExpanded="true"
OnPreRender="grd_View_PreRender" AllowMultiRowSelection="true" MasterTableView-EditFormSettings-EditColumn-AutoPostBackOnFilter="false"
Skin="Glassy" AllowMultiRowEdit="true">
<MasterTableView AutoGenerateColumns="False" HierarchyDefaultExpanded="true">
<AlternatingItemStyle CssClass="GridView-GroupHeaderItemStyle" />
<Columns>
<radG:GridTemplateColumn UniqueName="TemplateColumn" SortExpression="VSGroupBy">
<ItemTemplate>
<asp:Label ID="lblStatus" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, FIRSTGROUP).ToString() %>'> </asp:Label>
<asp:Label ID="lblStatus1" runat="server" Text='<%# GetGroupBy(DataBinder.Eval(Container.DataItem, FIRSTGROUP).ToString()) %>' />
<asp:Label ID="lblcnt" runat="server" Text='' />
</ItemTemplate>
<ItemStyle Width="100%" />
</radG:GridTemplateColumn>
</Columns>
<ExpandCollapseColumn>
<HeaderStyle Width="19px" />
</ExpandCollapseColumn>
<DetailTables>
<radG:GridTableView Width="100%" runat="server" AutoGenerateColumns="False" ShowHeader="True"
HierarchyLoadMode="ServerBind">
<HeaderStyle CssClass="GridView-HeaderStyle" Width="10%" />
<Columns>
<radG:GridTemplateColumn HeaderText="Header1" SortExpression="Header1">
<ItemTemplate>
<asp:Label ID="lblItem1" runat="server" Text='<%# Eval("RootCause").ToString()+ " " %>'></asp:Label>
</ItemTemplate>
<ItemStyle VerticalAlign="Top" />
<HeaderStyle Width="22%" Wrap="True" />
</radG:GridTemplateColumn>
<radG:GridTemplateColumn HeaderText="header2" SortExpression="" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblAgree" runat="server" CssClass='<%# Eval("lblitem2").ToString()=="N"?"AgreeStyles": ""%>' Text='<%# Eval("lblitem2").ToString()+ " " %>'></asp:Label>
</ItemTemplate>
<ItemStyle VerticalAlign="Top" />
<HeaderStyle Width="3%" Wrap="True" />
</radG:GridTemplateColumn>
<radG:GridTemplateColumn HeaderText="header3" SortExpression="What">
<ItemTemplate>
<asp:Label ID="lblitem3" runat="server" Text='<%# UIHelper.TextArea2HTML(Eval("lblitem3").ToString())+ " " %>'></asp:Label>
</ItemTemplate>
<ItemStyle VerticalAlign="Top" />
<HeaderStyle Width="15%" Wrap="True" />
</radG:GridTemplateColumn>
</Columns>
<PagerStyle Mode="NumericPages" Position="TopAndBottom" />
<EditFormSettings>
<EditColumn UniqueName="EditCommandColumn">
</EditColumn>
</EditFormSettings>
<AlternatingItemStyle CssClass="GridView-ItemStyle" />
<GroupHeaderItemStyle CssClass="GridView-GroupHeaderItemStyle" />
<ExpandCollapseColumn ButtonType="ImageButton" UniqueName="ExpandColumn" Visible="False">
<HeaderStyle Width="19px" />
</ExpandCollapseColumn>
<ItemStyle CssClass="GridView-ItemStyle" />
<RowIndicatorColumn UniqueName="RowIndicator" Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<NoRecordsTemplate>
There is no document to display
</NoRecordsTemplate>
</radG:GridTableView>
</DetailTables>
<NoRecordsTemplate>
There is no Actions to display
</NoRecordsTemplate>
<ExpandCollapseColumn Visible="False">
<HeaderStyle Width="19px" />
</ExpandCollapseColumn>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ItemStyle CssClass="GridView-GroupHeaderItemStyle" />
</MasterTableView>
<PagerStyle Mode="NumericPages" PageButtonCount="20" />
<HeaderStyle CssClass="GridView-HeaderStyle" />
<GroupHeaderItemStyle CssClass="GridView-GroupHeaderItemStyle" />
<ItemStyle CssClass="GridView-GroupHeaderItemStyle" />
<AlternatingItemStyle CssClass="GridView-GroupHeaderItemStyle" />
<PagerStyle Mode="NumericPages" Position="TopAndBottom" PageButtonCount="20" />
<FilterMenu HoverBackColor="LightSteelBlue" HoverBorderColor="Navy" NotSelectedImageUrl="~/RadControls/Grid/Skins/Default/NotSelectedMenu.gif"
SelectColumnBackColor="Control" SelectedImageUrl="~/RadControls/Grid/Skins/Default/SelectedMenu.gif"
TextColumnBackColor="Window"></FilterMenu>
<ClientSettings>
<Selecting AllowRowSelect="true"></Selecting>
</ClientSettings>
</radG:RadGrid>
Ok, several issues.
You are (it looks like) using a data pager - this can compliate things quite a bit.
Next, you using radgrid - so, a large % of the posters here - they may well not have an answer.
But, I do think the idea of tossing up a grid - let user edit, and then a SINGLE saved for all edits makes a WHOLE lot of sense. In fact, given that UI, then really no need for a edit buttion. all you really need/want is a save button, and then say a cancel/undo edits.
A really neat-o trick for above? Just persist the data source. Once you do that?
Then you allow the user to edit the grid - (no code required).
Then on save, you move grid edits back to the data talbe, and then in ONE NICE EASY update, send the data table back to the database. This results not only in VERY little code, but also provivdes a reather nice and un-cluttered UI to the user.
So, lets use a GridView. In fact, I OFTEN suggest to use a listview.
Why?
Well, with gridview (and the older datagrid), for each column control you drop in, you MUST put that standard control inside of "template" tags - so you require more (messy) markup.
But, lets do this with a simple gridview, and as you can see, not only is this easy, but we ALSO get .net to create the update statetments, and this we "leverage" the built in system to do all the dirty work.
So, say we have this grid:
<style> .borderhide input {border:none}</style>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
cssclass="table table-hover borderhide">
<Columns>
<asp:TemplateField HeaderText ="First Name">
<ItemTemplate>
<asp:TextBox ID="txtFirst" runat="server" Text = '<%# Eval("FirstName") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Last Name">
<ItemTemplate>
<asp:TextBox ID="txtLast" runat="server" Text = '<%# Eval("LastName") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="City">
<ItemTemplate>
<asp:TextBox ID="txtCity" runat="server" Text = '<%# Eval("City") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Active">
<ItemTemplate>
<asp:CheckBox ID="Active" runat="server" Checked = '<%# Eval("Active") %>'></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="cmdSave" runat="server" Text="Save" CssClass="btn-primary" OnClick="cmdSave_Click1" />
<asp:Button ID="cmdAdd" runat="server" Text="Add Row" CssClass="btn-primary" style="margin-left:20px"/>
<br />
Ok, not much markup.
So, now here is our code to fill the grid:
private DataTable rstPeople = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadGrid();
ViewState["MyTable"] = rstPeople;
Session["test"] = "hello";
}
else
rstPeople = (DataTable)ViewState["MyTable"];
}
public void LoadGrid()
{
using (SqlCommand cmdSQL = new SqlCommand("SELECT * from People",
new SqlConnection(Properties.Settings.Default.TEST4)))
{
cmdSQL.Connection.Open();
rstPeople.Load(cmdSQL.ExecuteReader());
GridView1.DataSource = rstPeople;
GridView1.DataBind();
}
}
Ok, but NOTE how we load the grid, but ALSO save (perist) the data table.
So, we now have this:
Ok, so you are now free to tab around - edit - it feels ALMOST like a spreadsheet.
Now, here is the save button to send the WHOLE set of edits back to database in one shot:
protected void cmdSave_Click1(object sender, EventArgs e)
{
// pull grid rows back to table.
foreach (GridViewRow rRow in GridView1.Rows)
{
int RecordPtr = rRow.RowIndex;
DataRow OneDataRow;
OneDataRow = rstPeople.Rows[RecordPtr];
OneDataRow["FirstName"] = ((TextBox)rRow.FindControl("txtFirst")).Text;
OneDataRow["LastName"] = ((TextBox)rRow.FindControl("txtLast")).Text;
OneDataRow["City"] = ((TextBox)rRow.FindControl("txtCity")).Text;
OneDataRow["Active"] = ((CheckBox)rRow.FindControl("Active")).Checked;
}
// now send table back to database with updates
string strSQL = "SELECT ID, FirstName, LastName, City, Active from People WHERE ID = 0";
using (SqlCommand cmdSQL = new SqlCommand(strSQL,
new SqlConnection(Properties.Settings.Default.TEST4)))
{
cmdSQL.Connection.Open();
SqlDataAdapter daupdate = new SqlDataAdapter(cmdSQL);
SqlCommandBuilder cmdBuild = new SqlCommandBuilder(daupdate);
daupdate.Update(rstPeople);
}
}
So, we send grid back to table.
We then send table back to database.
As you can see, this approach saves buckets of code.
the ONLY addtional issues here?
You are using a datapager. However, that means for each page navigation, re-bind the grid from that persisted table - do NOT re-load the data table from the database each time. But, a data pager complicates this VERY much, since on page navigation, we in theory would have to save the changes on that displayed page back to the table (we don't need to send table back to database, but we DO need to send possible changes from grid back to table. Thus, since navigation comes from that table, then this should work - and we not yet had to hit save to send persisted table back to database.
And note that the gridrow (and most controls) can return either the current page index or the overall index location of the row. So, I not done above with a datapager, but it should be possible to work.
And no real need for a edit button - I mean, what would edit do anyway? I don't think it is required - and just messes up the simple UI anyway.
And of course we should provide a cancel/undo. And all that would do is call LoadGrid again, and re-load grid from the database.
The above approaches should work with radGrid - but I never used it.
As noted, above idea works with GridView, listview and even older datagrid.
My preferred choice out of the 3 is actually list view, since as noted, you don't have to put messy template tags around each plain jane asp.net controls (such as text box, or as per above also a check box).
and the add row code in above, to allow adding a new row?
we have this:
protected void cmdAdd_Click(object sender, EventArgs e)
{
// add a new row to the grid
DataRow OneRow = rstPeople.Rows.Add();
GridView1.DataSource = rstPeople;
GridView1.DataBind();
}
Once again - really simple!!! and again it was easy since we operate against the table, and then just re-bind against the grid.
First let me preface this with the fact that I know this question has been asked a slew of times. I've tried implementing everything I've read and have not resolved my issue yet.
I have a shopping cart being displayed in a GridView and I am trying to get the update function to work. After I click edit (on the row in question) and I change the value in the textbox, and then click update, I am always getting an empty string returned.
I've read countless posts about it being a PostBack issue, however I have encapsulated my DataBind method within an if(!Page.IsPostBack){} so I dont believe that is my issue.
These are the relevant methods in my CodeFile:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["thisCart"] == null)
{
Session["thisCart"] = new ShoppingCart();
}
thisCart = (ShoppingCart)Session["thisCart"];
if (!Page.IsPostBack)
{
FillData();
}
}
private void FillData()
{
gvShoppingCart.DataSource = thisCart.Items;
gvShoppingCart.DataBind();
if (thisCart.Items.Count == 0)
{
lblGrandTotal.Visible = false;
}
else
{
lblGrandTotal.Text = string.Format("Grand Total = {0,19:C}", thisCart.GrandTotal);
lblGrandTotal.Visible = true;
}
}
protected void gvShoppingCart_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtQuantity = (TextBox)gvShoppingCart.Rows[e.RowIndex].Cells[3].Controls[0];
int quantity = Int32.Parse(txtQuantity.Text);
thisCart.Update(e.RowIndex, quantity);
gvShoppingCart.EditIndex = -1;
FillData();
}
And this is the aspx file:
<asp:GridView ID="gvShoppingCart" runat="server" AutoGenerateColumns="False" OnRowCancelingEdit="gvShoppingCart_RowCancelingEdit" OnRowDeleting="gvShoppingCart_RowDeleting" OnRowEditing="gvShoppingCart_RowEditing" OnRowUpdating="gvShoppingCart_RowUpdating" ClientIDMode="AutoID">
<Columns>
<asp:BoundField DataField="NAME" HeaderText="Product name" ReadOnly="True" />
<asp:ImageField DataImageUrlField="IMAGE" DataImageUrlFormatString="~\Images\{0}" HeaderText="Image" ReadOnly="True">
</asp:ImageField>
<asp:BoundField DataField="PRICE" HeaderText="Price" ReadOnly="True" />
<asp:BoundField DataField="QUANTITY" HeaderText="Quantity" />
<asp:TemplateField HeaderText="Total">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Double.Parse(Eval("PRICE").ToString()) * Int32.Parse(Eval("QUANTITY").ToString()) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
I'm usually pretty good at finding answers, but this one has got me stumped.
The site crashes after clicking update because the returned value from int quantity = Int32.Parse(txtQuantity.Text); is "" and obviously you cant parse an int from that.
As for the tag of possible duplicate of "ASP.NET validation error message to change labels text." I was unable to find anything that points me in the direction of an answer.
Call FillData() in Page_PreInit. Otherwise, when the ASP.Net runtime goes to restore ViewState for the grid, including your new Textbox data, there's nowhere to put it yet. Remember that every single server event uses a brand new instance of your page class and must rebuild the entire page from scratch.
This was a royal pain to figure out since I'm just learning ASP.net and C#.
When I was able to make this work on an earlier assignment I wasn't using a Master page, with this project I am. The problem lies in the fact that I am using a <form runat="server"> tag in the Master page. Since you can only have one <form runat="server"> tag per page, my GridView wasn't wrapped in one. Once I removed the Master page and added the <form runat="server"> wrapper around the GridView, everything works as intended.
I have a button inside a Gridview. What I want to do is when the button is clicked simply change the button color.
However, after publishing the paged and clicking the button nothing happens.
Am I missing a step.
Here is my .aspx code
<asp:GridView id="gvStatus" runat="server" AutoGenerateColumns="false" BorderWidth="1px" BackColor="White" CellPadding="3" CellSpacing="2" BorderStyle="Solid" BorderColor="Black" GridLines="Both" Pager="10" OnRowDataBound="setcolor" OnRowCommand="setsingle" >
<Columns>
<asp:TemplateField HeaderText="1" Visible="true" HeaderStyle-CssClass= "hdrBase" ItemStyle-CssClass="GridBase">
<ItemTemplate>
<asp:Button id="btnDOne" Width="35px" Height ="25px" runat="server" Text='<%#(Eval("dateone", "{0:ddd}"))%>' CommandName="GetData" CommandArgument="<%#((GridViewRow) Container).RowIndex %>" ></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And here is the c#
protected void setsingle(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "GetData")
{
//Get row index
int rowindex = Convert.ToInt32(e.CommandArgument);
////Get Row
GridViewRow gvr = gvStatus.Rows[rowindex];
//Find the button
Button DayButton = gvr.FindControl("btnDOne") as Button;
//Set the color of the button
DayButton.BackColor = Color.Cyan;
}
To test if the code was working added a linkbutton to the Gridview and gave it the same CommandName:
<asp:TemplateField HeaderText="1" Visible="true" HeaderStyle-CssClass= "hdrBase" ItemStyle-CssClass="GridBase">
<ItemTemplate>
<asp:Button id="btnDOne" Width="35px" Height ="25px" runat="server" Text='<%#(Eval("dateone", "{0:ddd}"))%>' CommandName="GetData" CommandArgument='<%# Container.DataItemIndex %>' ></asp:Button>
<asp:LinkButton id="lbd1" runat="server" Text="clickme " CommandName="GetData" CommandArgument='<%# Container.DataItemIndex %>'/>
</ItemTemplate>
</asp:TemplateField>
So, the linkbutton executes the behind code no problem. But the commandbutton does not execute anything. In the last code snippet you will notice I compared the two and basically made the commandbutton match the linkbutton as far as the CommandArgument goes.
I have verified the behind code works, as well as the CommandName assignment is correct.
Is there a different way to do this for a commandbutton?
I ended up abandoning the command buttons and going with the link buttons then setting the back-color of the Grid cell as needed.
I have a grid and I want to set a dropdown list with Yes & No for some columns. I am not able to put that dropdown list like I mentioned below. Its because I use checkbox in the grid to edit the rows. So even if I put these I am not able to see the drop down when I click the checkbox to edit.
<asp:TemplateField HeaderText="Lead" ItemStyle-Width="100">
<ItemTemplate>
<asp:Label ID="lblLead" runat="server" Text='<%# Bind("Lead") %>'></asp:Label>
<asp:TextBox ID="txtLead" runat="server" Text='<%# Bind("Lead") %>' Visible="false"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="100px" />
<EditItemTemplate>
<asp:DropDownList id="ddlLead" runat="server">
<asp:ListItem Value="Yes"> Yes </asp:ListItem>
<asp:ListItem Value="No"> No </asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
Try this
protected void grdVw_RowEditing(object sender, GridViewEditEventArgs e)
{
grdVw.EditIndex = e.NewEditIndex;
/* Insert specific editing logic here */
grdBind();//method to bind gridview
}
First you gotta make sure you are setting the mode to Edit. For this I use the default buttons, and you are using checkboxes, they should both work:
<asp:GridView ID="GridView1" runat="server" OnRowEditing="GridView1_RowEditing">
<Columns>
<asp:CommandField ShowEditButton="True" />
<%--Other columns here--%>
</Columns>
</asp:GridView>
Then, you need to handle the RowEditing event, by setting the EditIndex to the index of the row you want to edit, and re-bind the GridView:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
setDataSource(); //this sets the data source of the grid, and re-binds it.
}
I'm trying to add a delete column to my gridview, however when I press the delete button on a row, it calls the function I assigned to onRowDeleting infinitely or so it seems.
Here's my code:
<asp:GridView ID="GridView1" runat="server" CssClass="yep" AutoGenerateColumns="False" OnRowDeleting="dismissClick">
<Columns>
<asp:TemplateField HeaderText="Create Incident">
<ItemTemplate>
<asp:CheckBox ID="Selections" runat="server" ViewStateMode = "Enabled" OnCheckedChanged="CheckBox1_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="case#" HeaderText="Case #" SortExpression="case#" />
<asp:BoundField DataField="Unit #" HeaderText="Unit #" SortExpression="Unit #" />
<asp:BoundField DataField="date" HeaderText="date" SortExpression="date" />
<asp:BoundField DataField="typeOfCall" HeaderText="typeOfCall" SortExpression="typeOfCall" />
<asp:BoundField DataField="Primary Impression" HeaderText="Primary Impression" SortExpression="Primary Impression" />
<asp:TemplateField HeaderText="View PCR">
<ItemTemplate>
<asp:Button ID="ViewPCR" Text="View PCR" runat="server" OnClick="viewPCRClick" CssClass="btn em" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dismiss">
<ItemTemplate>
<asp:Button ID="dismiss" Text="Dismiss" runat="server" CommandName="Delete" CssClass="btn em" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and my simple deletion function:
protected void dismissClick(object sender, GridViewDeleteEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex);
GridView1.DeleteRow(index);
}
Calling GridView1.DeleteRow(index) is causing an event loop, because calling that method also raises the RowDeleted and RowDeleting events again, as described in the MSDN documentation for GridView.DeleteRow Method:
Calling this method also raises the RowDeleted and RowDeleting events.
Instead you want to either remove it from the binding source (i.e. DataSet, DataTable, List<T> or whatever you are binding to) or persist your delete to the database or whatever is ultimately holding your data and then re-bind the grid.