那位兄弟能提供一个asp.net的投票系统。我用vb.net做的。谢谢了!!! 你去www.aspxcn.com看看有没有,我记得以前在哪里看到过 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1 Recommend.aspx(推荐候选人页面)<%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.SqlClient" %><Script Language="VB" Runat="Server"> Sub addCandidate(sender As Object, e As Eventargs) Dim objConn As New SqlConnection() objConn.ConnectionString = "Data Source=localhost;Integrated Security=SSPI;" & _ "Initial Catalog=data" objConn.Open() Dim objCmd As New SqlCommand() objCmd.Connection = objConn objCmd.CommandText = "Select * From 候选人名单 Where 候选人='" & _ Name.Text & "'" Dim objReader As SqlDataReader = objCmd.ExecuteReader() If objReader.Read() = False Then objReader.Close() objCmd.CommandText = "Insert Into 候选人名单(候选人, 简介) Values('" & _ Name.Text & "', '" & Intro.Text & "')" objCmd.ExecuteNonQuery() objConn.Close() Response.Redirect("Default.aspx") Else objReader.Close() objConn.Close() errMessage.Text = "【" & Name.Text & "】" & "已经在候选人名单中了,不须要再推荐。" End If End Sub</Script><Html> <Head> <Title>推荐候选人</Title> </Head> <Body Bgcolor="#FFFAF0"> <P Align="Center"><Img Src="Title3.jpg"></P> <Form Runat="Server"> <Table Width="80%" Align="Center" Border="1" BorderColor="Blue"> <Tr BgColor="#FFFFCC"> <Td Align="Right">候选人姓名:</Td> <Td><Asp:TextBox Runat="Server" Id="Name" /></Td> </tr> <Tr> <Td BgColor="#CCFFCC" Align="Right">候选人简介:</Td> <Td BgColor="#CCFFCC"> <Asp:TextBox Runat="Server" Id="Intro" TextMode="MultiLine" Rows="5" Columns="30" /> </Td> </Tr> </Table> <Br> <Center> <Asp:LinkButton Runat="Server" Text="确定" OnClick="addCandidate" /> <A Href="Default.aspx">回主页</A> <P><Asp:Label Runat="Server" Id="errMessage" ForeColor="Red" /></P> </Center> </form> </Body></Html>2 首页 default.aspx<%@ Page Debug="true" %><%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.SqlClient" %><Script Language="VB" Runat="Server"> Dim ConnString As String Dim DS As New DataSet() Dim objCmd As SqlDataAdapter Sub CreateDataSet(strSQL As String, DataBaseName As String, TableName As String) ConnString = "Data Source=localhost;Integrated Security=SSPI;" & _ "Initial Catalog=" & DataBaseName objCmd = New SqlDataAdapter(strSQL, ConnString) objCmd.Fill(DS, TableName) End Sub Sub Page_Init(sender As Object, e As Eventargs) '添加第 1 行,并设置行属性 Dim myTableRow As New TableRow() myTableRow.HorizontalAlign= HorizontalAlign.Center myTableRow.BackColor = System.Drawing.Color.Honeydew myTableRow.ForeColor = System.Drawing.Color.RoyalBlue '添加第 1 行第 1 个字段 Dim myTableCell As New TableCell() myTableCell.Text = "候选人" myTableRow.Cells.Add(myTableCell) '添加第 1 行第 2 个字段 myTableCell = New TableCell() myTableCell.Text = "候选人介绍" myTableRow.Cells.Add(myTableCell) '将添加的行加入表格中 myTable.Rows.Add(myTableRow) '行出候选人列表 CreateDataSet("Select * From 候选人名单", "data", "候选人名单") Dim I As Integer For I = 0 to DS.Tables("候选人名单").Rows.Count - 1 '添加第 I + 2 行,并设置行属性 myTableRow = New TableRow() myTableRow.BackColor = System.Drawing.Color.BlanchedAlmond '添加第 I + 2 行第 1 个字段 myTableCell = New TableCell() Dim myCheckBox As New CheckBox() myCheckBox.Text = DS.Tables("候选人名单").Rows(I)("候选人") myTableCell.Controls.Add(myCheckBox) myTableRow.Cells.Add(myTableCell) '添加第 I + 2 行第 2 个字段 myTableCell = New TableCell() myTableCell.Text = DS.Tables("候选人名单").Rows(I)("简介") myTableRow.Cells.Add(myTableCell) myTable.Rows.Add(myTableRow) '将添加的行加入表格中 myTable.Rows.Add(myTableRow) Next '添加最後一行,并设置行属性 myTableRow = New TableRow() myTableRow.HorizontalAlign= HorizontalAlign.Right myTableRow.BackColor = System.Drawing.Color.Honeydew myTableRow.ForeColor = System.Drawing.Color.RoyalBlue '添加一个字段 myTableCell = New TableCell() myTableCell.ColumnSpan = 2 '加入一个 Label 控件 Dim myLabel As New Label() myLabel.Text = "请输入您的身份证号码:" myTableCell.Controls.Add(myLabel) '加入一个 TextBox 控件 Dim myTextBox As New TextBox() myTextBox.Columns = 12 myTableCell.Controls.Add(myTextBox) myTableRow.Cells.Add(myTableCell) '将添加的行加入表格中 myTable.Rows.Add(myTableRow) End Sub Sub Voting(sender As Object, e As Eventargs) '取得身份证号码字段,并将之转换为 TextBox 控件 Dim userId As TextBox = CType(myTable.Rows(myTable.Rows.Count - 1).Cells(0).Controls(1), TextBox) Dim strSQL As String = "Select * From 投票人名单 Where 身份证号码='" & userId.Text & "'" CreateDataSet(strSQL, "data", "投票人名单") '判断该身份证号码是否已经投过票 If DS.Tables("投票人名单").Rows.Count <> 0 Then errMessage.Text = "身份证号码 " & userId.Text & " 已经投过票了" Else '指定 InsertCommand 属性及其参数 objCmd.InsertCommand = New SqlCommand() objCmd.InsertCommand.CommandText = "Insert Into 投票人名单(身份证号码) Values (@身份证号码)" objCmd.InsertCommand.Connection = New SqlConnection(ConnString) objCmd.InsertCommand.Parameters.Add("@身份证号码", SqlDbType.NVarChar, 10, "身份证号码") '指定 UpdateCommand 属性及其参数 objCmd.UpdateCommand = New SqlCommand() objCmd.UpdateCommand.CommandText = "Update 候选人名单 Set 得票数=@新票数 " & _ "Where 候选人=@候选人" objCmd.UpdateCommand.Connection = New SqlConnection(ConnString) objCmd.UpdateCommand.Parameters.Add("@新票数", SqlDbType.Int, 4, "得票数") objCmd.UpdateCommand.Parameters.Add("@候选人", SqlDbType.NVarChar, 15, "候选人") '将投票者的身份证号码加入【投票人名单】数据表 Dim myRow As DataRow = DS.Tables("投票人名单").NewRow() myRow("身份证号码") = userId.Text DS.Tables("投票人名单").Rows.Add(myRow) '判断用户投给哪些候选人,然后将被投票人的票数加 1 Dim I As Integer For I = 0 To myTable.Rows.Count - 3 Dim myCheckBox As CheckBox = CType(myTable.Rows(I + 1).Cells(0).Controls(0), CheckBox) If myCheckBox.Checked Then DS.Tables("候选人名单").Rows(I)("得票数") += 1 End If Next '将 DataSet 对象实例的数据更新至数据库 objCmd.Update(DS, "投票人名单") objCmd.Update(DS, "候选人名单") Response.Redirect("Result.aspx") End If End Sub</Script><Html> <Head> <Title>在线投票</Title> </Head> <Body Bgcolor="#FFFAF0"> <P Align="Center"><Img Src="Title1.jpg"></P> <Form Runat="Server" > <Asp:Table Runat="Server" Id="myTable" Width="75%" HorizontalAlign="Center" BorderWidth="2" BorderColor="#999999" GridLines="Both" /> <P Align="Center"> <Asp:LinkButton Runat="Server" Text="投票" OnClick="Voting" /> <A Href="Recommend.aspx">推荐候选人</A> <A Href="Result.aspx">观看投票结果</A><Br><Br> <Asp:Label Runat="Server" Id="errMessage" ForeColor="Red" /> </P> </Form> </Body></Html> 3 result.aspx<!-- #include File="SqlFunction.inc" --><Script Language="VB" Runat="Server"> Sub Page_Load(sender As Object, e As Eventargs) '添加第 1 行,并设置行属性 Dim myTableRow As New TableRow() myTableRow.HorizontalAlign= HorizontalAlign.Center myTableRow.BackColor = System.Drawing.Color.Honeydew myTableRow.ForeColor = System.Drawing.Color.RoyalBlue '添加第 1 行第 1 个字段 Dim myTableCell As New TableCell() myTableCell.Text = "候选人" myTableRow.Cells.Add(myTableCell) '添加第 1 行第 2 个字段 myTableCell = New TableCell() myTableCell.Text = "得票数" myTableRow.Cells.Add(myTableCell) '添加第 1 行第 3 个字段 myTableCell = New TableCell() myTableCell.Text = "得票百分比" myTableRow.Cells.Add(myTableCell) '添加第 1 行第 4 个字段 myTableCell = New TableCell() myTableCell.Text = "直方图" myTableRow.Cells.Add(myTableCell) '将添加的行加入表格中 myTable.Rows.Add(myTableRow) Dim DS As DataSet = CreateDataSet("Select 候选人, 得票数 From 候选人名单 Order By 得票数 DESC", "data", "候选人名单") Dim I, TotalVote As Integer '计算总票数 For I = 0 To DS.Tables("候选人名单").Rows.Count - 1 TotalVote += DS.Tables("候选人名单").Rows(I)("得票数") Next '行出候选人得票数据 For I = 0 to DS.Tables("候选人名单").Rows.Count - 1 '添加第 x 行,并设置行属性 myTableRow = New TableRow() myTableRow.BackColor = System.Drawing.Color.BlanchedAlmond '添加第 I + 2 行第 1 个字段 myTableCell = New TableCell() myTableCell.Text = DS.Tables("候选人名单").Rows(I)("候选人") myTableRow.Cells.Add(myTableCell) '添加第 I + 2 行第 2 个字段 myTableCell = New TableCell() myTableCell.Text = DS.Tables("候选人名单").Rows(I)("得票数") myTableRow.Cells.Add(myTableCell) '添加第 I + 2 行第 3 个字段 myTableCell = New TableCell() myTableCell.Text = Math.Round(DS.Tables("候选人名单").Rows(I)("得票数") / TotalVote * 100, 2) & " %" myTableRow.Cells.Add(myTableCell) '添加第 I + 2 行第 4 个字段 myTableCell = New TableCell() Dim myImage As New HtmlImage() myImage.Src = "bar.jpg" myImage.Height = "20" myImage.Width = DS.Tables("候选人名单").Rows(I)("得票数") / TotalVote * 300 myTableCell.Controls.Add(myImage) myTableRow.Cells.Add(myTableCell) '将添加的行加入表格中 myTable.Rows.Add(myTableRow) Next '添加最后一行,并设置行属性 myTableRow = New TableRow() myTableRow.BackColor = System.Drawing.Color.BlanchedAlmond '添加最后一行第 1 个字段 myTableCell = New TableCell() myTableCell.Text = "总计" myTableRow.Cells.Add(myTableCell) '添加最后一行第 2 个字段 myTableCell = New TableCell() myTableCell.Text = TotalVote myTableRow.Cells.Add(myTableCell) '添加最后一行第 3 个字段 myTableCell = New TableCell() myTableCell.Text = "100 %" myTableRow.Cells.Add(myTableCell) '添加最后一行第 4 个字段 myTableCell = New TableCell() Dim fullImage As New HtmlImage() fullImage.Src = "bar.jpg" fullImage.Height = "20" fullImage.Width = "300" myTableCell.Controls.Add(fullImage) myTableRow.Cells.Add(myTableCell) '将添加的行加入表格中 myTable.Rows.Add(myTableRow) End Sub</Script><Html> <Head> <Title>在线投票</Title> </Head> <Body Bgcolor="#FFFAF0"> <P Align="Center"><Img Src="Title2.jpg"></P> <Form Runat="Server" > <Asp:Table Runat="Server" Id="myTable" Width="80%" HorizontalAlign="Center" BorderWidth="2" BorderColor="#999999" GridLines="Both" /> <P Align="Center"><A Href="Default.aspx">回主页</A></P> </Form> </Body></Html>4 sqlFunction.inc<%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.SqlClient" %><Script Languate="VB" Runat="Server"> 'strSQL 为 SQL 语句,FileName 为数据库文件名,TableName 为数据表名称。 Function CreateDataSet(strSQL As String, DataBaseName As String, TableName As String) As DataSet Dim ConnString As String = "Data Source=localhost;Integrated Security=SSPI;" & _ "Initial Catalog=" & DataBaseName Dim objCmd As New SqlDataAdapter(strSQL, ConnString) Dim DS As New DataSet() objCmd.Fill(DS, TableName) CreateDataSet = DS End Function</Script> 我留下我的油箱行不![email protected] vs中关于 ctrl + f 为什么要提交两次 SWFUpload + ASP.NET + IE8上传按钮不显示 gridview的问题 gridview模板列颜色设置 怎么在后台代码中找到前台的HTML控件? 非常急得一个问题(在线等) 博客列表和相册的实现? 请教同仁:如何将已建立的数据库(SQL Server)移植到另一机上。 我要死了 dropdownlist的很难问题!高手请进!! Session设置为20分钟失效。客户端正在输入数据超过20分钟但没提交,这时候Sesssion失效了吗?
1 Recommend.aspx(推荐候选人页面)<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<Script Language="VB" Runat="Server">
Sub addCandidate(sender As Object, e As Eventargs)
Dim objConn As New SqlConnection()
objConn.ConnectionString = "Data Source=localhost;Integrated Security=SSPI;" & _
"Initial Catalog=data"
objConn.Open()
Dim objCmd As New SqlCommand()
objCmd.Connection = objConn
objCmd.CommandText = "Select * From 候选人名单 Where 候选人='" & _
Name.Text & "'"
Dim objReader As SqlDataReader = objCmd.ExecuteReader() If objReader.Read() = False Then
objReader.Close()
objCmd.CommandText = "Insert Into 候选人名单(候选人, 简介) Values('" & _
Name.Text & "', '" & Intro.Text & "')"
objCmd.ExecuteNonQuery()
objConn.Close()
Response.Redirect("Default.aspx")
Else
objReader.Close()
objConn.Close()
errMessage.Text = "【" & Name.Text & "】" & "已经在候选人名单中了,不须要再推荐。"
End If
End Sub
</Script>
<Html>
<Head>
<Title>推荐候选人</Title>
</Head>
<Body Bgcolor="#FFFAF0">
<P Align="Center"><Img Src="Title3.jpg"></P>
<Form Runat="Server">
<Table Width="80%" Align="Center" Border="1" BorderColor="Blue">
<Tr BgColor="#FFFFCC">
<Td Align="Right">候选人姓名:</Td>
<Td><Asp:TextBox Runat="Server" Id="Name" /></Td>
</tr>
<Tr>
<Td BgColor="#CCFFCC" Align="Right">候选人简介:</Td>
<Td BgColor="#CCFFCC">
<Asp:TextBox Runat="Server" Id="Intro" TextMode="MultiLine"
Rows="5" Columns="30" />
</Td>
</Tr>
</Table>
<Br>
<Center>
<Asp:LinkButton Runat="Server" Text="确定" OnClick="addCandidate" />
<A Href="Default.aspx">回主页</A>
<P><Asp:Label Runat="Server" Id="errMessage" ForeColor="Red" /></P>
</Center>
</form>
</Body>
</Html>
2 首页 default.aspx<%@ Page Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<Script Language="VB" Runat="Server">
Dim ConnString As String
Dim DS As New DataSet()
Dim objCmd As SqlDataAdapter Sub CreateDataSet(strSQL As String, DataBaseName As String, TableName As String)
ConnString = "Data Source=localhost;Integrated Security=SSPI;" & _
"Initial Catalog=" & DataBaseName objCmd = New SqlDataAdapter(strSQL, ConnString)
objCmd.Fill(DS, TableName)
End Sub Sub Page_Init(sender As Object, e As Eventargs)
'添加第 1 行,并设置行属性
Dim myTableRow As New TableRow()
myTableRow.HorizontalAlign= HorizontalAlign.Center
myTableRow.BackColor = System.Drawing.Color.Honeydew
myTableRow.ForeColor = System.Drawing.Color.RoyalBlue '添加第 1 行第 1 个字段
Dim myTableCell As New TableCell()
myTableCell.Text = "候选人"
myTableRow.Cells.Add(myTableCell) '添加第 1 行第 2 个字段
myTableCell = New TableCell()
myTableCell.Text = "候选人介绍"
myTableRow.Cells.Add(myTableCell) '将添加的行加入表格中
myTable.Rows.Add(myTableRow) '行出候选人列表
CreateDataSet("Select * From 候选人名单", "data", "候选人名单")
Dim I As Integer
For I = 0 to DS.Tables("候选人名单").Rows.Count - 1 '添加第 I + 2 行,并设置行属性
myTableRow = New TableRow()
myTableRow.BackColor = System.Drawing.Color.BlanchedAlmond '添加第 I + 2 行第 1 个字段
myTableCell = New TableCell()
Dim myCheckBox As New CheckBox()
myCheckBox.Text = DS.Tables("候选人名单").Rows(I)("候选人")
myTableCell.Controls.Add(myCheckBox)
myTableRow.Cells.Add(myTableCell) '添加第 I + 2 行第 2 个字段
myTableCell = New TableCell()
myTableCell.Text = DS.Tables("候选人名单").Rows(I)("简介")
myTableRow.Cells.Add(myTableCell)
myTable.Rows.Add(myTableRow) '将添加的行加入表格中
myTable.Rows.Add(myTableRow)
Next '添加最後一行,并设置行属性
myTableRow = New TableRow()
myTableRow.HorizontalAlign= HorizontalAlign.Right
myTableRow.BackColor = System.Drawing.Color.Honeydew
myTableRow.ForeColor = System.Drawing.Color.RoyalBlue '添加一个字段
myTableCell = New TableCell()
myTableCell.ColumnSpan = 2 '加入一个 Label 控件
Dim myLabel As New Label()
myLabel.Text = "请输入您的身份证号码:"
myTableCell.Controls.Add(myLabel) '加入一个 TextBox 控件
Dim myTextBox As New TextBox()
myTextBox.Columns = 12
myTableCell.Controls.Add(myTextBox)
myTableRow.Cells.Add(myTableCell) '将添加的行加入表格中
myTable.Rows.Add(myTableRow)
End Sub Sub Voting(sender As Object, e As Eventargs)
'取得身份证号码字段,并将之转换为 TextBox 控件
Dim userId As TextBox = CType(myTable.Rows(myTable.Rows.Count - 1).Cells(0).Controls(1), TextBox) Dim strSQL As String = "Select * From 投票人名单 Where 身份证号码='" & userId.Text & "'"
CreateDataSet(strSQL, "data", "投票人名单") '判断该身份证号码是否已经投过票
If DS.Tables("投票人名单").Rows.Count <> 0 Then
errMessage.Text = "身份证号码 " & userId.Text & " 已经投过票了"
Else '指定 InsertCommand 属性及其参数
objCmd.InsertCommand = New SqlCommand()
objCmd.InsertCommand.CommandText = "Insert Into 投票人名单(身份证号码) Values (@身份证号码)"
objCmd.InsertCommand.Connection = New SqlConnection(ConnString)
objCmd.InsertCommand.Parameters.Add("@身份证号码", SqlDbType.NVarChar, 10, "身份证号码") '指定 UpdateCommand 属性及其参数
objCmd.UpdateCommand = New SqlCommand()
objCmd.UpdateCommand.CommandText = "Update 候选人名单 Set 得票数=@新票数 " & _
"Where 候选人=@候选人"
objCmd.UpdateCommand.Connection = New SqlConnection(ConnString)
objCmd.UpdateCommand.Parameters.Add("@新票数", SqlDbType.Int, 4, "得票数")
objCmd.UpdateCommand.Parameters.Add("@候选人", SqlDbType.NVarChar, 15, "候选人") '将投票者的身份证号码加入【投票人名单】数据表
Dim myRow As DataRow = DS.Tables("投票人名单").NewRow()
myRow("身份证号码") = userId.Text
DS.Tables("投票人名单").Rows.Add(myRow) '判断用户投给哪些候选人,然后将被投票人的票数加 1
Dim I As Integer
For I = 0 To myTable.Rows.Count - 3
Dim myCheckBox As CheckBox = CType(myTable.Rows(I + 1).Cells(0).Controls(0), CheckBox)
If myCheckBox.Checked Then
DS.Tables("候选人名单").Rows(I)("得票数") += 1
End If
Next '将 DataSet 对象实例的数据更新至数据库
objCmd.Update(DS, "投票人名单")
objCmd.Update(DS, "候选人名单")
Response.Redirect("Result.aspx")
End If
End Sub
</Script>
<Html>
<Head>
<Title>在线投票</Title>
</Head>
<Body Bgcolor="#FFFAF0">
<P Align="Center"><Img Src="Title1.jpg"></P>
<Form Runat="Server" >
<Asp:Table Runat="Server" Id="myTable" Width="75%" HorizontalAlign="Center"
BorderWidth="2" BorderColor="#999999" GridLines="Both" />
<P Align="Center">
<Asp:LinkButton Runat="Server" Text="投票" OnClick="Voting" />
<A Href="Recommend.aspx">推荐候选人</A>
<A Href="Result.aspx">观看投票结果</A><Br><Br>
<Asp:Label Runat="Server" Id="errMessage" ForeColor="Red" />
</P>
</Form>
</Body>
</Html>
<Script Language="VB" Runat="Server">
Sub Page_Load(sender As Object, e As Eventargs)
'添加第 1 行,并设置行属性
Dim myTableRow As New TableRow()
myTableRow.HorizontalAlign= HorizontalAlign.Center
myTableRow.BackColor = System.Drawing.Color.Honeydew
myTableRow.ForeColor = System.Drawing.Color.RoyalBlue '添加第 1 行第 1 个字段
Dim myTableCell As New TableCell()
myTableCell.Text = "候选人"
myTableRow.Cells.Add(myTableCell) '添加第 1 行第 2 个字段
myTableCell = New TableCell()
myTableCell.Text = "得票数"
myTableRow.Cells.Add(myTableCell) '添加第 1 行第 3 个字段
myTableCell = New TableCell()
myTableCell.Text = "得票百分比"
myTableRow.Cells.Add(myTableCell) '添加第 1 行第 4 个字段
myTableCell = New TableCell()
myTableCell.Text = "直方图"
myTableRow.Cells.Add(myTableCell) '将添加的行加入表格中
myTable.Rows.Add(myTableRow) Dim DS As DataSet = CreateDataSet("Select 候选人, 得票数 From 候选人名单 Order By 得票数 DESC", "data", "候选人名单")
Dim I, TotalVote As Integer '计算总票数
For I = 0 To DS.Tables("候选人名单").Rows.Count - 1
TotalVote += DS.Tables("候选人名单").Rows(I)("得票数")
Next '行出候选人得票数据
For I = 0 to DS.Tables("候选人名单").Rows.Count - 1
'添加第 x 行,并设置行属性
myTableRow = New TableRow()
myTableRow.BackColor = System.Drawing.Color.BlanchedAlmond '添加第 I + 2 行第 1 个字段
myTableCell = New TableCell()
myTableCell.Text = DS.Tables("候选人名单").Rows(I)("候选人")
myTableRow.Cells.Add(myTableCell) '添加第 I + 2 行第 2 个字段
myTableCell = New TableCell()
myTableCell.Text = DS.Tables("候选人名单").Rows(I)("得票数")
myTableRow.Cells.Add(myTableCell) '添加第 I + 2 行第 3 个字段
myTableCell = New TableCell()
myTableCell.Text = Math.Round(DS.Tables("候选人名单").Rows(I)("得票数") / TotalVote * 100, 2) & " %"
myTableRow.Cells.Add(myTableCell) '添加第 I + 2 行第 4 个字段
myTableCell = New TableCell()
Dim myImage As New HtmlImage()
myImage.Src = "bar.jpg"
myImage.Height = "20"
myImage.Width = DS.Tables("候选人名单").Rows(I)("得票数") / TotalVote * 300
myTableCell.Controls.Add(myImage)
myTableRow.Cells.Add(myTableCell) '将添加的行加入表格中
myTable.Rows.Add(myTableRow)
Next '添加最后一行,并设置行属性
myTableRow = New TableRow()
myTableRow.BackColor = System.Drawing.Color.BlanchedAlmond '添加最后一行第 1 个字段
myTableCell = New TableCell()
myTableCell.Text = "总计"
myTableRow.Cells.Add(myTableCell) '添加最后一行第 2 个字段
myTableCell = New TableCell()
myTableCell.Text = TotalVote
myTableRow.Cells.Add(myTableCell) '添加最后一行第 3 个字段
myTableCell = New TableCell()
myTableCell.Text = "100 %"
myTableRow.Cells.Add(myTableCell) '添加最后一行第 4 个字段
myTableCell = New TableCell()
Dim fullImage As New HtmlImage()
fullImage.Src = "bar.jpg"
fullImage.Height = "20"
fullImage.Width = "300"
myTableCell.Controls.Add(fullImage)
myTableRow.Cells.Add(myTableCell) '将添加的行加入表格中
myTable.Rows.Add(myTableRow)
End Sub
</Script>
<Html>
<Head>
<Title>在线投票</Title>
</Head>
<Body Bgcolor="#FFFAF0">
<P Align="Center"><Img Src="Title2.jpg"></P>
<Form Runat="Server" >
<Asp:Table Runat="Server" Id="myTable" Width="80%" HorizontalAlign="Center"
BorderWidth="2" BorderColor="#999999" GridLines="Both" />
<P Align="Center"><A Href="Default.aspx">回主页</A></P>
</Form>
</Body>
</Html>4 sqlFunction.inc<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<Script Languate="VB" Runat="Server">
'strSQL 为 SQL 语句,FileName 为数据库文件名,TableName 为数据表名称。
Function CreateDataSet(strSQL As String, DataBaseName As String, TableName As String) As DataSet
Dim ConnString As String = "Data Source=localhost;Integrated Security=SSPI;" & _
"Initial Catalog=" & DataBaseName
Dim objCmd As New SqlDataAdapter(strSQL, ConnString)
Dim DS As New DataSet()
objCmd.Fill(DS, TableName)
CreateDataSet = DS
End Function
</Script>
[email protected]