English 中文(简体)
如何用vb.net添加Gridview囚室?
原标题:How to add the Gridview cells using vb.net?

My Gridview has following Fields

ID          Product            Price ($)
1           Pencil             1
2           Pen                1
3           Rubber             2

我想计算Grudview 标语......的总价格。

总价格=4

如何使用VB。 NET?

最佳回答

http://msdn.microsoft.com/en-us/library/ms972833.aspx”rel=“nofollow” GridView ASP.NET 2.0: 显示脚注数据

问题回答

采用可计算数据的方法,以获得所有价格的总和,并处理罗达塔·博恩通,以制定脚注案文:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            BindData()
        End If
    End Sub

    Private Sub BindData()
        Dim tbl As New DataTable
        Dim col As New DataColumn("ID", GetType(Int32))
        tbl.Columns.Add(col)
        col = New DataColumn("Product", GetType(String))
        tbl.Columns.Add(col)
        col = New DataColumn("Price", GetType(Double))
        tbl.Columns.Add(col)
        Dim row As DataRow = tbl.NewRow
        row("ID") = 1
        row("Product") = "Pencil"
        row("Price") = 1
        tbl.Rows.Add(row)
        row = tbl.NewRow
        row("ID") = 1
        row("Product") = "Pen"
        row("Price") = 1
        tbl.Rows.Add(row)
        row = tbl.NewRow
        row("ID") = 1
        row("Product") = "Rubber"
        row("Price") = 2
        tbl.Rows.Add(row)
        Me.GridView1.ShowFooter = True
        Me.GridView1.DataSource = tbl
        Me.GridView1.DataBind()
    End Sub

    Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.Footer Then
            Dim tbl As DataTable = DirectCast(GridView1.DataSource, DataTable)
            Dim total As Double = DirectCast(tbl.Compute("SUM(Price)", Nothing), Double)
            e.Row.Cells(2).Text = total.ToString
        End If
    End Sub
Sub BindAmount()
    Dim r As DataGridViewRow

    If DataGridView1.RowCount > 0 Then
        Dim TAmt As Decimal = 0.0

        For Each r In DataGridView1.Rows
            If r.Visible = True Then
                TAmt = TAmt + r.Cells("PRICE").Value
                TXT_PRICE.Text = TAmt
            End If
        Next
    Else
         TXT_PRICE.Text = 0
    End If
End Sub

**LOAD ON KEYDOWN





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签