用ASP.NET 2.0设计网络在线投票系统(3)
2008-02-22 09:28:01来源:互联网 阅读 ()
3.添加功能
单击页面VoteItemManage.aspx中的【增加新的投票项目】按钮,触发事件AddBtn_Click(object sender, System.EventArgs e),该事件实现添加一个新的投票项目。事件AddBtn_Click(object sender, System.EventArgs e)的程序代码如下:
| private void AddBtn_Click(object sender, System.EventArgs e) { if (Item.Text.Length > 0) { //定义类 WebVote.Vote vote = new Vote(); try { //添加新数据项 vote.AddVote(Item.Text.Trim()); BindVoteListData(); //显示操作结果信息 Response.Write("<script>window.alert('" ASPNET2System.OPERATIONADDSUCCESSMESSAGE "')</script>"); } catch (Exception ex) { //显示添加操作中的失败、错误信息 Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl=" ASPNET2System.RedirectErrorUrl(Request.RawUrl) "&ErrorMessage=" ex.Message.Replace("\n", " ")); } } } |
4.删除功能
单击页面VoteItemManage.aspx中的【×】按钮,触发事件deleteBtn_Click(object sender, System.EventArgs e),该事件实现删除已选择的投票项目。事件deleteBtn_Click(object sender, System.EventArgs e)的程序代码如下:
| protected void deleteBtn_Click(object sender, ImageClickEventArgs e) { if (ItemList.SelectedIndex <= -1) { //显示操作结果信息 Response.Write("<script>window.alert('" ASPNET2System.OPERATIONNOSELECTMESSAGE "')</script>"); return; } //定义类 WebVote.Vote vote = new Vote(); try { //删除数据 vote.DeleteVote(Int32.Parse(ItemList.SelectedValue)); //重新绑定数据 BindVoteListData(); } catch (Exception ex) { //显示删除操作中的失败、错误信息 Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl=" ASPNET2System.RedirectErrorUrl(Request.RawUrl) "&ErrorMessage=" ex.Message.Replace("\n", " ")); } } |
在应用程序WebVote中添加一个新的Web页面,并命名为WebOnlineVote.aspx,它的代码隐藏文件为WebOnlineVote.aspx.cs文件。
1.页面设计
在页面WebOnlineVote.aspx上添加一个数据网格控件、两个Button控件和一个Label控件,它们的名称分别为VoteList、VoteBtn、ShowVote和VoteMessage。控件VoteList用来显示参与投票的所有项目;控件VoteBtn提交用户的投票;控件ShowVote实现用户查看投票情况;控件VoteMessage显示用户投票的操作结果。页面WebOnlinVote.aspx的设计界面如图6所示。

图6 页面WebOnlinVote.aspx的设计界面
页面WebOnlinVote.aspx的HTML设计代码如下:
| <%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebOnlinVote.aspx.cs" Inherits="WebOnlinVote" %> <HTML><HEAD><title>网络在线投票系统</title></HEAD> <asp:datagrid id="VoteList" CssClass="GbText" Runat="server" AutoGenerateColumns="False" DataKeyField="VoteID"> <Columns> <asp:TemplateColumn ItemStyle-Width="200"> <ItemTemplate><%# DataBinder.Eval(Container.DataItem,"Item")%> </ItemTemplate></asp:TemplateColumn> <asp:TemplateColumn ItemStyle-Width="100"> <ItemTemplate> <asp:CheckBox ID="VoteCheck" Runat="server"></asp:CheckBox> </ItemTemplate></asp:TemplateColumn> </Columns> <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" /> <SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" /> <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" /> <ItemStyle BackColor="White" ForeColor="#330099" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" /> </asp:datagrid> <asp:button id="VoteBtn" Runat="server" Width="100" Text="我要投票"></asp:button> <asp:button id="ShowVote" Runat="server" Width="100" Text="查看投票"></asp:button> <asp:Label ID="VoteMessage" Runat="server" Visible="False" ForeColor="red" Font-Bold="True">投票成功!!!</asp:Label></td> </HTML> |
1.页面初始化
页面WebOnlinVote.aspx调用函数Page_Load(Object sender,EventArgs e)初始化,该函数调用函数BindVoteListData()从数据库投票表Votes中获取所有投票项目的信息,并把获取的数据设置为数据网格控件VoteList的数据源。函数Page_Load(Object sender,EventArgs e)和函数BindVoteListData()的程序代码如下:
| private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack) { //绑定投票的项目 BindVoteListData(); VoteMessage.Visible = false; 标签: 版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
相关文章
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设 网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源 网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它 服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护 软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷 网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash 热门词条
最新资讯
热门关注
|
