ติดปัญหาเรื่อง DataGridView แสดงข้อมูลแบบ Double ครับ
โค๊ดแบบนี้ครับ
Code (VB.NET)
Private Sub BindDataGridB()
Dim dt As New DataTable
Dim Adapter As SqlDataAdapter
objConn = New SqlConnection(strConnString)
objConn.Open()
objCmd = New SqlCommand
objCmd = objConn.CreateCommand()
objCmd.CommandText = "SELECT [buy].idbuy,[buy].nobill,[buy].amount,[buy].price,[buy].total,[buy].pay,[buy].type,[buy].day,[buy].month,[buy].year,[buy].time,[customer].name FROM [buy] INNER JOIN [customer] ON [buy].idcus = [customer].idcus"
objCmd.CommandType = CommandType.Text
Adapter = New SqlDataAdapter(objCmd)
Adapter.Fill(dt)
objConn.Close()
Me.dgvB.DataSource = dt
Me.dgvB.Columns.Clear()
Dim column As DataGridViewTextBoxColumn
column = New DataGridViewTextBoxColumn()
column.DataPropertyName = "idbuy"
Me.dgvB.Columns.Add(column)
column = New DataGridViewTextBoxColumn()
column.DataPropertyName = "nobill"
column.HeaderText = "เลขที่บิล"
column.Width = 100
Me.dgvB.Columns.Add(column)
column = New DataGridViewTextBoxColumn()
column.DataPropertyName = "name"
column.HeaderText = "ชื่อ-นามสกุล"
column.Width = 200
Me.dgvB.Columns.Add(column)
column = New DataGridViewTextBoxColumn()
column.DataPropertyName = "amount"
column.HeaderText = "จำนวน"
column.Width = 60
Me.dgvB.Columns.Add(column)
column = New DataGridViewTextBoxColumn()
column.DataPropertyName = "price"
column.HeaderText = "ราคา"
column.Width = 80
Me.dgvB.Columns.Add(column)
column = New DataGridViewTextBoxColumn()
column.DataPropertyName = "total"
column.HeaderText = "รวม"
column.Width = 80
Me.dgvB.Columns.Add(column)
column = New DataGridViewTextBoxColumn()
column.DataPropertyName = "time"
column.HeaderText = "เวลา"
column.Width = 60
Me.dgvB.Columns.Add(column)
column = New DataGridViewTextBoxColumn()
column.DataPropertyName = "pay"
column.HeaderText = "ชำระเงิน"
column.Width = 90
Me.dgvB.Columns.Add(column)
column = New DataGridViewTextBoxColumn()
column.DataPropertyName = "type"
column.HeaderText = "ประเภท"
column.Width = 60
Me.dgvB.Columns.Add(column)
column = New DataGridViewTextBoxColumn()
column.DataPropertyName = "day"
column.HeaderText = "วันที่"
column.Width = 60
Me.dgvB.Columns.Add(column)
column = New DataGridViewTextBoxColumn()
column.DataPropertyName = "month"
column.HeaderText = "เดือน"
column.Width = 60
Me.dgvB.Columns.Add(column)
column = New DataGridViewTextBoxColumn()
column.DataPropertyName = "year"
column.HeaderText = "ปี"
column.Width = 60
Me.dgvB.Columns.Add(column)
dt = Nothing
Me.dgvB.Columns(0).Visible = False
End Sub
อยากให้แสดงข้อมูลแบบ double ตรง total ซึ่งรูปแบบประมาณ x,xxx.xx ไม่ทราบว่าต้องแก้อย่างไรครับ แล้วนำไปคำนวนต่อได้ไหมครับTag : .NET, Ms SQL Server 2012
Date :
2013-04-29 15:51:23
By :
fujisawa10
View :
796
Reply :
3
Code (VB.NET)
Protected Sub dgvB_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles dgvB.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'ColumnIndex = N
Dim txt As Double = CType(e.Row.Cells(ColumnIndex).Text, Double)
e.Row.Cells(ColumnIndex).Text = Format(txt, "N0").ToString
EndIf
หรือ
Dim txt As Double = CType(e.Row.DataItem("total").ToString, Double)
ประวัติการแก้ไข 2013-04-29 16:39:31 2013-04-29 16:41:04
Date :
2013-04-29 16:37:53
By :
mee079
Load balance : Server 02