Binding of gridview totals in repeater not working - c#

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;
}
}

Related

assign a value to checkbox in a grid in code behind

I have following grid in asp.net
<asp:GridView ID="grdDWlocations" CssClass="table table-hover table-striped" runat="server" GridLines="None" ShowHeaderWhenEmpty="True"
EmptyDataText="No data found..." AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="" Visible="true">
<HeaderTemplate>
<asp:CheckBox ID="allDWlocchk" runat="server" Checked="true" Width="10px" onclick="CheckAllgrdReqDW(this)"></asp:CheckBox>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk_DWlocReq" runat="server" Checked="true" Width="5px" OnCheckedChanged="chk_Req_CheckedChangedDW_Click" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Code">
<ItemTemplate>
<asp:Label ID="lbl_DWCode" runat="server" Text='<%# Bind("Ml_loc_cd") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lbl_DWDescription" runat="server" Text='<%# Bind("Ml_loc_desc") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I want to assign value for "chk_DWlocReq" in code behind
like this
foreach (GridViewRow dgvr in grdDWlocations.Rows)
{
(CheckBox)dgvr.FindControl("chk_DWlocReq")=true;
}
but above one not valid, how can this do properly ?
I believe your code must be changed to:
foreach (GridViewRow dgvr in grdDWlocations.Rows)
{
((CheckBox)dgvr.FindControl("chk_DWlocReq")).Checked=true;
}
Use this:
foreach(GridViewRow row in GridView1.Rows) {
if(row.RowType == DataControlRowType.DataRow) {
CheckBox myCheckBoxID = row.FindControl("myCheckBoxID") as CheckBox;
}
myCheckBoxID.Checked = true;
}
OR
If you are handling RowDataBound event, it's like this:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox myCheckBoxID = e.Row.FindControl("myCheckBoxID") as CheckBox;
}
myCheckBoxID.Checked = true;
}
Try the following:
CheckBox checkbox1 = dgvr.FindControl("chk_DWlocReq") as CheckBox;
checkbox1.Checked = true;
I used this code:
ds1.SelectCommand = String.Format("exec myStoredproc");
dv1 = (DataView)ds1.Select(DataSourceSelectArguments.Empty);
for (int i = 0; i < GridView1.Rows.Count; i++)
{
if (dv1.Table.Rows[i]["ReceiveNotification"].ToString() == "1")
{
((CheckBox)GridView1.Rows[i].FindControl("GV_chkNotification")).Checked = true;
}
else
{
((CheckBox)GridView1.Rows[i].FindControl("GV_chkNotification")).Checked = false;
}
}

How to Find label control value in Gridview Footer ButtonClick Event

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 ");
}
}

Dynamic postbackurl

I'm having a problem calling a modal in asp
I need to set the postbackurl of linkbutton4 from code behind depending on what is selected in the dropdownlist! I have tried putting the postbackurl directlty on the linkbuttons tag it worked but when i change it from the code behind it doesnt BTW i change it when the link button is clicked.
Code behind for the linkbutton:
protected void LinkButton4_Click(object sender, EventArgs e)
{
var a = (Control)sender;
GridViewRow row = (GridViewRow)a.NamingContainer;
string b = row.Cells[0].Text;
Session["C"] = b;
DropDownList ddl =(DropDownList)row.Cells[7].FindControl("DropDownList1");
Session["D"] = ddl.SelectedItem.Text;
LinkButton lb = (LinkButton)row.Cells[7].FindControl("LinkButton4");
if (Session["D"].ToString() == "Upload")
{
lb.PostBackUrl = "preprod_design.aspx#edit";
// Upload();
}
if (Session["D"].ToString() == "Download")
{
Download();
}
infogridbind();
}
Here is the code for aspx :
<asp:GridView ID="GridView2" runat="server" ondatabound="GridView2_DataBound"
onrowdatabound="GridView2_RowDataBound"
onrowcreated="GridView2_RowCreated"
onselectedindexchanged="GridView2_SelectedIndexChanged"
onrowcommand="GridView2_RowCommand" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="SizeSetID" SortExpression="SizeSetID"/>
<asp:BoundField DataField="Revision No." SortExpression="RevisionNo" HeaderText = "Revision No."/>
<asp:TemplateField HeaderText ="Image">
<ItemTemplate>
<asp:Image ID="Image2" runat="server" onError = "this.style.display = 'none';" ImageUrl='<%#"~/ClientPoImage.ashx?autoId="+Eval("[SizeSetID]")%>' Width="50px" Height="40px"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Size Name" SortExpression="SizeName" HeaderText = "Size Name"/>
<asp:BoundField DataField="Quantity Requested" SortExpression="QuantityRequested" HeaderText ="Quantity Requested"/>
<asp:BoundField DataField="Quantity Received" SortExpression="QuantityReceived" HeaderText="Quantity Received"/>
<asp:BoundField DataField="Balance" SortExpression="Balance" HeaderText="Balance"/>
<asp:TemplateField HeaderText="Action">
<ItemTemplate >
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
<asp:ListItem>Upload</asp:ListItem>
<asp:ListItem>Download</asp:ListItem>
<asp:ListItem>Edit</asp:ListItem>
<asp:ListItem>Delete</asp:ListItem>
<asp:ListItem>Request</asp:ListItem>
<asp:ListItem>Receive</asp:ListItem>
</asp:DropDownList>
<asp:LinkButton ID="LinkButton4" runat="server" onclick="LinkButton4_Click">GO</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You can change PostBackUrl for LinkButton inside DropDownList.SelectedIndexChanged event like this
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
var ddl = (DropDownList)sender;
var row = (GridViewRow)(ddl.NamingContainer);
var lb = (LinkButton)row.FindControl("LinkButton4");
if (ddl.SelectedValue == "Upload")
{
lb.PostBackUrl = "preprod_design.aspx#edit";
}
if (ddl.SelectedValue == "Download")
{
....
}
}
also you need change markup like this
....
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
....
Remove AutoPostBack="True" From DropDownList, and in the header of page <%# Page Title="data"... EnableEventValidation="false" %>
After That You just go to click event of Link button and then
GridViewRow gr = (GridViewRow)(((LinkButton)sender).NamingContainer);
DropDownList ddl = (DropDownList)gr.FindControl("DropDownList1");
If(ddl.SelectedValue =="Upload") // or u can use ddl.SelectedItem.Text
{
//Upload();
}
else if(ddl.SelectedValue == "Download")
{
//Download();
}

how to get button find control value in nested grid using c#

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.

Changing the footer text in GridView

I can't seem to be able to change the footer text. I've tried the sorted event as well but nothing happens. All I want to do is display status messages. Here is my code:
protected void PageSettings_Sorting(object sender, GridViewSortEventArgs e)
{
if (((GridView)sender).EditIndex > -1)
{
e.Cancel = true;
}
else
{
// tried this on sorted aswell but can't change footer text
GridViewRow row = ((GridView)sender).FooterRow as GridViewRow;
Label lblStatus = new Label{ ID="lblStatus", Text="Sorting Column <b>\"" + e.SortExpression + "\" " + e.SortDirection + "</b>"};
row.Cells[0].Text = "Hello World"; //.Controls.Add(lblStatus);
}
}
protected void PageSettings_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row != null && e.Row.RowType == DataControlRowType.Header)
{
}
else if (e.Row != null && e.Row.RowType == DataControlRowType.Footer)
{
int count = e.Row.Cells.Count;
for (int i = count - 1; i >= 1; i += -1)
{
e.Row.Cells.RemoveAt(i);
}
e.Row.Cells[0].ColumnSpan = count;
e.Row.Cells[0].Controls.Add(new Literal { ID = "lblStatus" });
// can't FindControl or change Literals either
e.Row.Cells[0].Text = "Hello World"; // works here but not on sorting event
}
}
<asp:GridView ID="PageSettings" runat="server"
AllowPaging="true" AllowSorting="true"
AutoGenerateColumns="false"
AutoGenerateDeleteButton="true"
AutoGenerateEditButton="true"
ShowFooter="true"
DataSourceID="ObjectDataSourcePages"
OnLoad="PageSettings_Load"
OnRowDataBound="PageSettings_DataBound"
OnRowCreated="PageSettings_RowCreated"
OnRowEditing="PageSettings_RowEditing"
OnRowCancelingEdit="PageSettings_RowCancelingEdit"
OnPageIndexChanging="PageSettings_PageIndexChanging"
OnSorting="PageSettings_Sorting"
OnSorted="PageSetting_Sorted"
PageSize="2">
<Columns>
<asp:TemplateField HeaderText="Page Name" HeaderStyle-HorizontalAlign="Left" SortExpression="Name">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Name" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Path" HeaderStyle-HorizontalAlign="Left" SortExpression="Path">
<ItemTemplate>
<%# Eval("Path") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Path" runat="server" Text='<%# Bind("Path") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Route Value" HeaderStyle-HorizontalAlign="Left" SortExpression="RouteValue">
<ItemTemplate>
<%# Eval("RouteValue") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="RouteValue" runat="server" Text='<%# Bind("RouteValue") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="RegExp" HeaderStyle-HorizontalAlign="Left" SortExpression="RegExp">
<ItemTemplate>
<%# Eval("RegExp") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="RegExp" runat="server" Text='<%# Bind("RegExp") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
This will change the text of the first FooterRow cell:
protected void gv_Sorting(object sender, GridViewSortEventArgs e)
{
gv.FooterRow.Cells[0].Text = "Hello";
}
Of course you'll need to make sure your GridView's ShowFooter property is true.
Or alternatively, by casting sender and adding a control:
protected void Sorting(object sender, GridViewSortEventArgs e)
{
Label label = new Label();
label.Text = gv_s.Rows.Count.ToString() + " records";
((GridView)sender).FooterRow.Cells[0].Controls.Add(label);
}

Categories