我的一个ASP.net简单查询实现
来源:互联网 发布:如何开农村淘宝服务站 编辑:程序博客网 时间:2024/05/02 19:13
Imports System.Data
Imports System.Data.OleDb
.....
'Initialize the query string
Dim strName, strYear, strSQL As String
Dim rTmp As DataRow
strYear = lstYear.SelectedValue
If RadioTeam.Checked = True Then
strName = lstTeam.SelectedValue
strSQL = "SELECT * FROM QueryTeamWV WHERE TeamName = '" & strName & "' And WorkYear=" & strYear
End If
....
'Create connection to one access database, and get data
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & Server.MapPath("App_Data/WV.mdb")
Dim objConn As New OleDbConnection(sConnectionString)
objConn.Open()
Dim objCmdSelect As New OleDbCommand(strSQL, objConn)
Dim objAdapter1 As New OleDbDataAdapter()
objAdapter1.SelectCommand = objCmdSelect
Dim objDataset1 As New DataSet()
objAdapter1.Fill(objDataset1, "wvData")
'how to add one additional row to temp table
rTmp = objDataset1.Tables(0).NewRow
rTmp("TeamName") = "Total"
rTmp("Jan") = SumJan
rTmp("Feb") = SumFeb
rTmp("Mar") = SumMar
rTmp("Apr") = SumApr
rTmp("May") = SumMay
rTmp("Jun") = SumJun
rTmp("Jul") = SumJul
。。。。
objDataset1.Tables(0).Rows.Add(rTmp)
'Display result
gvTeam.DataSource = objDataset1.Tables(0).DefaultView
gvTeam.DataBind()
'Follow procedure are called by RowDataBound event to format the data.
'display diff with red when negative
Private Sub NumNegative(ByVal gvTmp As GridView)
Dim gvr As GridViewRow
For Each gvr In gvTmp.Rows
If Not String.IsNullOrEmpty(gvr.Cells(gvr.Cells.Count - 1).Text) Then
If CInt(gvr.Cells(gvr.Cells.Count - 1).Text) < 0 Then
gvr.Cells(gvr.Cells.Count - 1).ForeColor = Drawing.Color.Red
End If
End If
Next
End Sub
Private Sub GrouGV(ByVal gvTmp As GridView, ByVal e As System.EventArgs)
If radioDept.Checked = True Then
GroupRows(gvTmp, e, "Team", 1)
GroupRows(gvTmp, e, "Dept", 0)
Else
GroupRows(gvTmp, e, "Name", 0)
End If
End Sub
'将指定列分组合并
Private Sub GroupRows(ByVal gvTmp As GridView, ByVal e As System.EventArgs, ByVal strType As String, ByVal intColumn As Integer)
Dim text As String
text = ""
Dim count As Integer
count = 0
Dim ht As Hashtable
ht = New Hashtable
' loop through all rows to get row counts
Dim gvr As GridViewRow
For Each gvr In gvTmp.Rows
If (gvr.RowType = DataControlRowType.DataRow) Then
If (gvr.Cells(intColumn).Text = text) Then
count = count + 1
Else
If (count > 0) Then
ht.Add(strType + text, count)
End If
text = gvr.Cells(intColumn).Text
count = 1
End If
End If
Next
If (count > 1) Then ht.Add(strType + text, count)
'loop through all rows again to set rowspan
text = ""
For Each gvr In gvTmp.Rows
If (gvr.RowType = DataControlRowType.DataRow) Then
If gvr.Cells(intColumn).Text = text Then
gvr.Cells.Remove(gvr.Cells(intColumn))
Else
text = gvr.Cells(intColumn).Text
gvr.Cells(intColumn).RowSpan = Convert.ToInt32(ht(strType + text))
End If
End If
Next
End Sub
'Two small tips:
1. 如何让系统自动为Radio Button生成后台的事件代码需要将其属性:AutoPostBack=True
2. 定义grid view中数据格式,例如显示一位小数的数字:{0:N1},需要将列属性中的HtmlEncode=False,才能生效
- 我的一个ASP.net简单查询实现
- 怎样用asp.net实现简单的查询功能
- 一个实现查询功能的asp.net控件
- ASP.NET三层架构的一个简单实现
- ASP.NET : 一个网站繁体转换的简单实现
- 一个简单的asp.net 单点登录实现
- asp.net core 实现一个简单的仓储
- asp.net 实现一个简单CAS Server
- ASP.NET ATLAS 的一个简单例子
- ASP.Net生成一个简单的图片
- 一个简单的ASP.NET +ACCESS 登录
- 一个简单的asp.net动态页面
- 一个简单的AJAX实现,基于C#的ASP.Net,包括服务器端的程序代码
- 一个简单的AJAX实现,基于C#的ASP.Net,包括服务器端的程序代码
- ASP.NET实现简单的验证码
- ASP.NET实现简单的文字水印
- ASP.NET 实现简单的权限控制
- 基于ASP.NET的comet简单实现
- 我想回家
- 使用yui-ext中的createCallback把函数的作用域绑定到window
- 进入存储行业了,推荐一个好网站
- JavaScript web开发技术
- 解读Windows Live Custom Domains 详细教程
- 我的一个ASP.net简单查询实现
- VMWare 应用好文
- 消息中间件和JMS
- linux下配置,启动多个tomcat
- (转)PS/2 PC键盘编程的参考资料
- Hibernate多对一 的处理
- c#多线程编程笔记1
- CVS服务器设置指南
- c#多线程编程笔记2