Gridview Aspx Page
<asp:GridView ID="GridView2" runat="server" ShowFooter="true" GridLines="None" AutoGenerateColumns="False" CssClass="table table-hover">
<Columns>
<asp:TemplateField HeaderText="S.no">
<ItemTemplate><%#Container.DataItemIndex+1 %>
<asp:Label ID="lblReqNo1" Visible="false" runat="server" Text='<%#Eval("ReqNo")%>' ></asp:Label>
<asp:Label ID="lblFranchise_id" Visible="false" runat="server" Text='<%#Eval("franchise_id")%>' ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAccept" runat="server" CssClass="btn btn-danger"
Text="Accept Request" onclick="btnAccept_Click" />
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Product Name" DataField="p_name" />
<asp:BoundField HeaderText="Quantity" DataField="Qty" />
<asp:BoundField HeaderText="Dealer Price" DataField="DP" />
<asp:BoundField HeaderText="Amount" DataField="amt" />
</Columns>
</asp:GridView>
C# Code
Button Click event which is in Gridview Footer Template
protected void btnAccept_Click(object sender, EventArgs e)
{
// GridViewRow row = (GridViewRow)((sender as Button).NamingContainer);
using (GridViewRow row = (GridViewRow)((Button)sender).NamingContainer)
{
Label lblReqNo = (Label)row.FindControl("lblReqNo1");
Label lblFranchise_id = (Label)row.FindControl("lblFranchise_id");
objFund.Transfer_id = int.Parse(lblReqNo.Text);
objFund.Type = 9;
int a = objFund.Insert();
objFund.Transfer_id = int.Parse(lblFranchise_id.Text);//franchise Id
objFund.CreditAmt = float.Parse(lblReqNo.Text);
objFund.Type = 5;
int b = objFund.Insert();
if (b > 0)
{
msg.Alert("Request accepted and mount Debited ");
}
}
}
it throws exception which is below
Object reference not set to an instance of an object.
Label lblReqNo = (Label)row.FindControl("lblReqNo1");//
by this line I'm getting only Null Values.How do i find Label Value?
Thanks
You can check row type wether it is header row or data row...
.. i.e. if it is data row then only your code will will execute
if (row.RowType == DataControlRowType.DataRow)
{
Label lblReqNo = (Label)row.FindControl("lblReqNo1");
Label lblFranchise_id = (Label)row.FindControl("lblFranchise_id");
objFund.Transfer_id = int.Parse(lblReqNo.Text);
objFund.Type = 9;
int a = objFund.Insert();
objFund.Transfer_id = int.Parse(lblFranchise_id.Text);//franchise Id
objFund.CreditAmt = float.Parse(lblReqNo.Text);
objFund.Type = 5;
int b = objFund.Insert();
if (b > 0)
{
msg.Alert("Request accepted and mount Debited ");
}
}
Related
I have an embedded gridview in my repeater. On the repeater itemdatabound I'm binding the gridview and trying to retrieve the totals that will be displayed in the gridviewfooters, however, the totals are not working, what am I missing?
Please could someone help
Cheers
<asp:Repeater ID="rpt" runat="server" onitemdatabound="rpt_ItemDataBound" >
<HeaderTemplate>
<table>
<tr>
<td>
<asp:Label ID="lblName" runat="server" ClientIDMode="Static"></asp:Label>
</td>
<td>
<asp:Label ID="lblAddress" runat="server" ClientIDMode="Static"></asp:Label>
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<asp:HiddenField ID="hfID" runat="server" Value='<%# DataBinder.Eval(Container, "DataItem.link_id") %>' />
<asp:GridView ID="grd" ClientIDMode="Static" runat="server"
Width="100%" DataKeyNames="ID" AutoGenerateColumns="False" GridLines="Vertical"
CellPadding="4" AllowPaging="True" AllowCustomPaging="True" PageSize="25" PagerStyle-Visible="False"
ShowFooter="true" OnRowDataBound="grd_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="hfID" runat="server" ClientIDMode="Static" Value='<%# DataBinder.Eval(Container,"DataItem.id") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="code" DataField="code" />
<asp:BoundField HeaderText="Description" DataField="desc" />
<asp:BoundField HeaderText="Qty" DataField="quantity" />
<asp:BoundField HeaderText="Employee Paid" DataField="e_total" />
<asp:BoundField HeaderText="Client Charged" DataField="c_total" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:Repeater>
code behind
double dEmpTotal = 0;
double dClientTotal = 0;
protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
int ID = int.Parse(((HiddenField)e.Item.FindControl("hfID")).Value);
GridView grd = (GridView)e.Item.FindControl("grd");
DataContext dc = new DataContext(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
var qry = from p in dc.usp_list_costs(ID)
select p;
List<usp_list_costsResult> lstCosts = new List<usp_list_costsResult>();
lstCosts = qry.ToList();
double dEmpTotal = Convert.ToDouble(lstCosts.Sum(r => r.emp_total));
double dClientTotal = Convert.ToDouble(lstCosts.Sum(r => r.client_total));
grd.DataSource = lstCosts;
grd.DataBind();
}
}
protected void grd_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[4].Text = "Employee Total:" + dEmpTotal;
e.Row.Cells[5].Text = "Client Total:" + dClientTotal;
}
}
I assumed that your totals are always zero, because you try to get dEmpTotal and dClientTotal values while handling grd_RowDataBound with row type is Footer, but the values were set to zero at that time.
You have to set the total values when it's binding data to repeater item, in rpt_ItemDataBound event handler instead.
So you don't need to set Footer rows' value in grd_RowDataBound method at all.
The code should be like this (Just adding the last two rows as my sample code)
protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
int ID = int.Parse(((HiddenField)e.Item.FindControl("hfID")).Value);
GridView grd = (GridView)e.Item.FindControl("grd");
DataContext dc = new DataContext(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
var qry = from p in dc.usp_list_costs(ID)
select p;
List<usp_list_costsResult> lstCosts = new List<usp_list_costsResult>();
lstCosts = qry.ToList();
double dEmpTotal = Convert.ToDouble(lstCosts.Sum(r => r.emp_total));
double dClientTotal = Convert.ToDouble(lstCosts.Sum(r => r.client_total));
grd.DataSource = lstCosts;
grd.DataBind();
grd.FooterRow.Cells[4].Text = "Employee Total:" + dEmpTotal;
grd.FooterRow.Cells[5].Text = "Client Total:" + dClientTotal;
}
}
I have added programatically button to the footer in RowDataBound:
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[1].Text = "Total: ";
e.Row.Cells[2].Text = totalStaff.ToString();
Button showStaff = new Button();
showStaff.CommandName = "ShowAll";
showStaff.Text = e.Row.Cells[2].Text.ToString();
e.Row.Cells[2].Controls.Add(showStaff);
e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Right;
showStaff.Click += new EventHandler(showStaff_Click);
}
now I want to handle showStaff_Click to bind data to nested gridview. I wrote bwlow code in RowCommand but index is null:
if(e.CommandName == "ShowAll")
{
int index = Convert.ToInt32(e.CommandArgument.ToString());
GridViewRow row = Staff.Rows[index];
GridView StaffInfo = (GridView)Staff.Rows[index].FindControl("StaffInfo");
int TeamID = 0;
int cityID = 3699;
StaffInfo.DataSource = GetStaff(cityID, TeamID);
StaffInfo.DataBind();
}
I will appreciate Your help.
EDIT:
I have nade some changes:
protected void Staff_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
//Checking for command name which command/button is pressed
if (e.CommandName == "ShowDetails")
{
GridView Staff = (GridView)sender;
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = Staff.Rows[index];
GridView StaffInfo = (GridView)Staff.Rows[index].FindControl("StaffInfo");
int TeamID = Convert.ToInt16(Staff.DataKeys[index].Values[0].ToString());
int cityID = Convert.ToInt16(Staff.DataKeys[index].Values[1].ToString());
StaffInfo.DataSource = GetStaff(cityID, TeamID);
StaffInfo.DataBind();
StaffInfo.Visible = true;
}
else if(e.CommandName == "ShowAll")
{
int index = Convert.ToInt32(e.CommandArgument);
GridView StaffInfo = (GridView)Staff.Rows[index].FindControl("StaffInfo");
int TeamID = 0;
int cityID = 3699;
StaffInfo.DataSource = GetStaff(cityID, TeamID);
StaffInfo.DataBind();
StaffInfo.Visible = true;
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
<asp:GridView ID="Staff" runat="server" AutoGenerateColumns="false"
OnRowCommand="Staff_RowCommand"
DataKeyNames="TeamID,CityID" ShowFooter="True" HorizontalAlign="Center">
<Columns>
<asp:TemplateField HeaderText=" Function">
<ItemTemplate>
<asp:Label Width="150px" ID="Function" ItemStyle-HorizontalAlign="Center" runat="server" Text='<%# Bind("Function") %>'></asp:Label>
<asp:GridView ID="StaffInfo" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="FirstName" HeaderText="First Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="LastName" HeaderText="Last Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="SOEID" HeaderText="SOEID" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=" Team">
<ItemTemplate>
<asp:Label Width="150px" ID="Team" ItemStyle-HorizontalAlign="Center" runat="server" Text='<%# Bind("Team") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Staff Count">
<ItemTemplate>
<asp:Button Width="40px" ID="StaffCount" ItemStyle-HorizontalAlign="Center" runat="server" Text='<%# Bind("StaffCount") %>' CommandName="ShowDetails" CommandArgument="<%# ((GridViewRow)Container).RowIndex %>" CausesValidation="True" UseSubmitBehavior="False" />
</ItemTemplate>
<FooterTemplate>
<asp:Button id="TotalStaff" runat="server" Text="Button1" CommandName="ShowAll" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" CausesValidation="True" UseSubmitBehavior="False" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField Visible ="false">
<ItemTemplate>
<asp:Label runat="server" Width="150px" DataField="TeamID" HeaderText="TeamID" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible ="false">
<ItemTemplate>
<asp:Label runat="server" ItemStyle-Width="150px" DataField="CityID" HeaderText="CityID"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
When I try to click the ShowAll button ite returns that index is out of range. I made Response.Write(intex.ToString()) and it returns -1. The index number in case or row is returned correctly. The problem is with footer button. Could You please help me?
You did not set CommandArgument when you crated your button.
Button showStaff = new Button();
showStaff.CommandName = "ShowAll";
showStaff.CommandArgument = e.Row.RowIndex.ToString();
showStaff.Text = e.Row.Cells[2].Text.ToString();
I am using the below code to read gridview controls value or text. But it return null value. I can't find out. But the gridview having some record with the value. Please help me to solve this.
GridViewRow row = null;
for (int i = 0; i < grd.Rows.Count; i++)
{
row = grd.Rows[i];
HiddenField file_id = (HiddenField)row.FindControl("FLD_ID");
Label pack_name = (Label)row.FindControl("FLD_NAME");
string text = file_id.Value;
bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;
if (isChecked)
{
//Here its comming
}
}
My partial gridview code here
<asp:GridView ID="grd" runat="server" BackColor="#CCCCCC" BorderColor="#93afba"
BorderStyle="Solid" BorderWidth="1px" CellPadding="4" AllowPaging="True" AutoGenerateColumns="False"
ShowHeaderWhenEmpty="True" PageSize="50" Width="100%" CellSpacing="2" ForeColor="#93afba"
Font-Size="14px">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<%--<asp:CheckBox ID="chkall" runat="server" OnChange="checkAll();" />--%>
<input id="Checkbox2" type="checkbox" onclick="CheckAll(this)" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
<ItemStyle Width="20px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="FLD_ID" Visible="false">
<ItemTemplate>
<asp:HiddenField ID="lbl_id" runat="server" Value='<%#Bind("FLD_ID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NAME">
<ItemTemplate>
<asp:Label ID="lbl_packname" runat="server" Text='<%#Bind("FLD_NAME") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
i think you want to find Checkbox2 and you are finding chkSelect
please replace this
bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;
with
bool isChecked = ((System.Web.UI.HtmlControls.HtmlInputCheckBox)grd_proforma_bill.HeaderRow.FindControl("Checkbox2")).Checked;
your code is fine.
if you are binding gridview on page load be sure your code is as below block
if (!IsPostBack)
{
//code to bind gridview
}
Change the code to and check:
for (int i = 0; i < grd_proforma_bill.Rows.Count; i++)
{
HiddenField file_id = (HiddenField)grd_proforma_bill.Rows[i].FindControl("lbl_id");
Label pack_name = (Label)grd_proforma_bill.Rows[i].FindControl("lbl_packname");
string text = file_id.Value;
CheckBox cb = (CheckBox)grd_proforma_bill.Rows[i].FindControl("Checkbox2");
bool isChecked = cb.Checked;
if (isChecked)
{
//Here its comming
}
}
I am using Nested GridViews where each row in the gridview has child gridView. I am using RowDataBound Event of Parent GridView, to Binding Child GridView. My Problem is that, how to get Child GridView's Button findcontrol value in Parent gridViews RowDataBound Event.
This is my Aspx page
<asp:GridView ID="grdSubClaimOuter" SkinID="GridView" runat="server" Width="100%"
AutoGenerateColumns="false" OnRowDataBound="grdSubClaimOuter_RowDataBound" OnRowCommand="grdSubClaimOuter_RowCommand"
ShowFooter="false" AllowPaging="true" OnPageIndexChanging="grdSubClaimOuter_PageIndexChanging">
<%--<AlternatingRowStyle BackColor="ButtonFace" />--%>
<Columns>
<asp:TemplateField ItemStyle-Width="5%">
<ItemTemplate>
<asp:HiddenField ID="hdnClaimNo" runat="server" Value='<%# Eval("ClaimNo") %>' />
<asp:Image runat="server" ID="img1" ImageUrl="../images/Collapse_plus.png" />
</ItemTemplate>
<ItemStyle Width="5%"></ItemStyle>
</asp:TemplateField>
<asp:GridView ID="grdSubClaim" runat="server" SkinID="GridView" CellPadding="4" Width="100%"
AutoGenerateColumns="false" ShowFooter="false" OnRowEditing="grdSubClaim_RowEditing"
OnRowCommand="grdSubClaim_RowCommand" OnRowDeleting="grdSubClaim_RowDeleted"
AllowPaging="false" >
<%--SkinID="GridView"--%>
<Columns>
<asp:TemplateField FooterStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
Sub Claim No
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblSubClaimNoValue" Width="" runat="server" Text='<%#Eval("SubClaimNo")%>'></asp:Label>
</ItemTemplate>
<FooterStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:Button ID="btnSubrogation" CssClass="groovybutton" runat="server" CommandName="Subrogation"
Text="Subrogation" CommandArgument='<%# Eval("ClaimNo") + "~" + Eval("SubClaimNo")%>' />
<asp:Button ID="btnSalvage" CssClass="groovybutton" runat="server" CommandName="Salvage"
Text="Salvage" CommandArgument='<%# Eval("ClaimNo") + "~" + Eval("SubClaimNo")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle CssClass="" />
<RowStyle CssClass="ob_gBody" />
<HeaderStyle CssClass="gridHeader" />
</asp:GridView>
<asp:Literal runat="server" ID="Literal2" Text="</td></tr>" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
This is My aspx.cs file
protected void grdSubClaimOuter_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text.ToString() != " ")
{
Literal ltrChild = (Literal)e.Row.FindControl("ltrChild");
System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)e.Row.Cells[0].FindControl("img1");
ltrChild.Text = ltrChild.Text.Replace("trChildGrid", "trChildGrid" + e.Row.RowIndex.ToString());
string strChildGrid = "trChildGrid" + e.Row.RowIndex.ToString();
e.Row.Cells[0].Attributes.Add("OnClick", "OpenTable('" + strChildGrid + "','" + img.ClientID + "')");
e.Row.Cells[0].RowSpan = 1;
System.Web.UI.WebControls.GridView gvChild = (System.Web.UI.WebControls.GridView)e.Row.FindControl("grdSubClaim");
PolicyProcessor.DAL.Claim.ClaimSubClaim objDALClaimSubClaim = new PolicyProcessor.DAL.Claim.ClaimSubClaim();
PolicyProcessor.BOL.Claim.ClaimSubClaim objInfoClaimSubClaim = new PolicyProcessor.BOL.Claim.ClaimSubClaim();
HiddenField hdnClaimNo = (HiddenField)e.Row.FindControl("hdnClaimNo");
if (hdnClaimNo.Value != "")
{
objInfoClaimSubClaim.ClaimNo = hdnClaimNo.Value;
}
else
{
objInfoClaimSubClaim.ClaimNo = "0";
}
DataSet dsChild;
dsChild = objDALClaimSubClaim.ResultSet(objInfoClaimSubClaim, "SelectInnerGrid");
if (dsChild.Tables[0].Rows.Count > 0)
{
Button btn = (Button)gvChild.FindControl("btnSalvage");
//btn is null how to get text value in btn
btn.ForeColor = System.Drawing.Color.Red;
gvChild.DataSource = dsChild;
gvChild.DataBind();
}
else
{
Helper.EmptyGrid(gvChild, dsChild.Tables[0]);
}
}
}
}
if anyone knows it,please help me solve this problem.thanks in advance.
First get a reference to the child GridView, then use FindControl to get the Button inside it:
foreach (GridViewRow row in grdSubClaimOuter.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
GridView gvChild = (GridView) row.FindControl("grdSubClaim");
// Then do the same method for Button control column
if (gvChild != null)
{
foreach (GridViewRow row in gvChild .Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
Button btn = (Button ) row.FindControl("buttonID");
if (btn != null )
{
// do your work
}
}
}
}
}
}
If you want value in parent grid's data bound event then use either way
1)You can also use your dsChild(Your dataset) and get field value which you are binding for button.
2) Get value of button from gvChild after binding child grid.
No need to loop into parent and child grid.
cs code
protected void DeleteNewRowToGrid()
{
int rowIndex = 0;
if (ViewState["dtCurrentTable"] != null)
{
DataTable DeldtCurrentTable = (DataTable)ViewState["dtCurrentTable"];
DataRow drCurrentRow = null;
if (DeldtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i > DeldtCurrentTable.Rows.Count; i--)
{
//extract the TextBox values
TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
//TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
DropDownList box2 = (DropDownList)Gridview1.Rows[rowIndex].Cells[2].FindControl("ddldatatype");
drCurrentRow = DeldtCurrentTable.NewRow();
drCurrentRow["RowNumber"] = i - 1;
drCurrentRow["Column1"] = box1.Text;
drCurrentRow["Column2"] = box2.Text;
//drCurrentRow["Column3"] = box3.Text;
rowIndex--;
}
//add new row to DataTable
DeldtCurrentTable.Rows.Remove(drCurrentRow);
//Store the current data to ViewState
ViewState["dtCurrentTable"] = DeldtCurrentTable;
//Rebind the Grid with the current data
Gridview1.DataSource = DeldtCurrentTable;
Gridview1.DataBind();
}
}
}
protected void ButtonDel_Click(object sender, EventArgs e)
{
DeleteNewRowToGrid();
}
aspx code
<asp:gridview ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Column Name">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:TemplateField HeaderText="Header 2">
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="Data Type">
<ItemTemplate>
<asp:DropDownList ID="ddldatatype" runat="server">
<asp:ListItem>varchar</asp:ListItem>
<asp:ListItem>int</asp:ListItem>
<asp:ListItem>numeric</asp:ListItem>
<asp:ListItem>uniqueidentifier</asp:ListItem>
<asp:ListItem>char</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" OnClick="ButtonAdd_Click"/>
<asp:Button ID="ButtonDel" runat="server" Text="Delete Row" OnClick="ButtonDel_Click"/>
<input type="hidden" runat="server" value="0" id="hiddencount" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
I have done with add rwo, now I want to delete
you are trying to deleta a row "drCurrentRow" that's not even in your DataTable, because you created this drCurrentRow = DeldtCurrentTable.NewRow(); yourself and didn't even insert it (no use anyway).
You have to search the rows to delete from your source like this:
var toDel = DeldtCurrentTable.Where(row => /* true if found */).ToArray();
foreach(var t in toDel) DeldtCurrentTable.Rows.Remove(t);
and then you can reiterate and set your rownumbers again.
Finaly set the the ViewState and the DataSource + DataBind it
BTW: your naming is really frustrating - what the heck does "DeleteNewRowToGrid" mean? Do you want to delete some new row? What is the a new row in this case?
So: Which row should be deleted here?