2012年12月21日 星期五

2012年12月8日 星期六

VB.NET 控制項變數名稱


   For i As Integer = 1 To 4
            CType(Me.Controls("label" & i), Label).Text = i
        Next

2012年12月4日 星期二

加總GridView內某欄位


dim  count as integer
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
'個人習慣將要加的欄位轉成template
 If e.Row.RowType = DataControlRowType.DataRow Then   
   dim countval as label = e.Row.FindControl("加總欄位id") 
   count += CType(countval.Text, Integer)
 elseIf e.Row.RowType = DataControlRowType.Footer Then
   e.Row.Cells(0).Text = "總分:"
   e.Row.Cells(1).Text = count  
 end if

end sub

DataTable的某個欄位作加總


DataTable dt = new DataTable();
string s_sum = dt .Compute("SUM(欄位名稱)", "").ToString();

取得 SqlDataSource 中Select 的結果做為DataSet 或 DataTable


取得 SqlDataSource 中Select 的結果做為DataSet 或 DataTable
'取得查詢結果
'使用DataView來取得sqlDataSource中 select 產生的結果
Dim dv As DataView = sqlDataSource1.Select(New DataSourceSelectArguments)