DATAGRID与数据库绑定,显示内容为姓名 买彩票次数 中奖次数
--------------------------------------
张三 20 2
李四 18 4
刘明 30 5
现需增加一列姓名 买彩票次数 中奖次数 中奖机率
-----------------------------------------------------
张三 20 2 中奖次数/买彩票次数 (%)
李四 18 4 22%
刘明 30 5 16%如何实现呢? 程序怎么写呀(vb)
--------------------------------------
张三 20 2
李四 18 4
刘明 30 5
现需增加一列姓名 买彩票次数 中奖次数 中奖机率
-----------------------------------------------------
张三 20 2 中奖次数/买彩票次数 (%)
李四 18 4 22%
刘明 30 5 16%如何实现呢? 程序怎么写呀(vb)
a.HeaderText = "中奖机率";
this.DataGrid1.Columns.Add(a);在ItemCommand事件中写下:
try
{
e.Item.Cells[3].Text = Convert.ToString(Convert.ToInt32(e.Item.Cells[2].Text)/Convert.ToInt32(e.Item.Cells[1].Text) * 100) + "%"
}
catch
{}
a.HeaderText = "中奖机率";
this.DataGrid1.Columns.Add(a);VB中
dim a as new datagridcolumn
好像不行呀怎么办呢?
e.Item.Cells(4).Text = Convert.ToString(Convert.ToInt32(e.Item.Cells(3)) / Convert.ToInt32(e.Item.Cells(2).Text) * 100) + "%" Catch ex As Exception End Try
End Sub
就不是应在page_load中dim a as new datagridcolumn
如:select 姓名,买彩票次数, 中奖次数,中奖次/买彩票次数 as 中奖机率 from Table
_____________________________________________
中奖机率只有0 ,如何实现小数位呢?或者百分比,因为现在他只是整型
select 姓名,买彩票次数, 中奖次数,case when 买彩票次数>0 then 中奖次/买彩票次数 end as 中奖机率 from Table
姓名 买彩票次数 中奖次数 中奖机率
-----------------------------------------------------
公司1 40 12 0
公司1 67 12 0
上面是最后得出的结果