Gridview页脚模板的价值发挥作用 [英] Gridview Footer Template value to working
本文介绍了Gridview页脚模板的价值发挥作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用gridview页脚模板显示薪水总额.
但是,当在gridview rowdata绑定中找到此控件时,它会显示一些错误.
Hi,
I am using gridview footer template for displaying sum of salary.
but, when find this control in gridview rowdata bound it''s shows some error.
Error : Object reference not set to an instance of an object.
我想计算所有值并显示在页脚标注标签中.
该怎么做...?
ASPX页面
---------
I want to calculate all the values and display in footer lbltotal lables.
How to do this...?
ASPX Page
---------
<asp:TemplateField HeaderText="Salary" ItemStyle-Width="65%">
<ItemTemplate>
<asp:TextBox ID="txtSal" runat="server" ForeColor="Blue" Width="75%" Text='<%# Eval("Sal") %>' ReadOnly="true" MaxLength="7"></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="LBLTotal" runat="server" ForeColor="Green"></asp:Label>
</FooterTemplate>
<ItemStyle HorizontalAlign="Center"/>
</asp:TemplateField>
ASPX.Vb代码
-------------
ASPX.Vb Code
-------------
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim sum As Integer = 0
For index As Integer = 0 To GridView1.Rows.Count - 1
If CStr(Me.GridView1.Rows(index).Cells(12).Text) <> "" Then
sum += Convert.ToInt32(Me.GridView1.Rows(index).Cells(12).Text)
End If
Dim Tot As Label = DirectCast(GridView1.FindControl("LBLTotal"), Label)
Tot.Text = sum
Next
End If
End Sub
推荐答案
您需要使用
you need to use
If e.Row.RowType = DataControlRowType.Footer Then
//your code here
End If
有关更多详细信息,请单击链接:
在ASP.NET C#VB.NET中的Gridview页脚中运行总计
For more detail follow the link:
Running Total In Gridview Footer in ASP.NET C# VB.NET
这篇关于Gridview页脚模板的价值发挥作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文