您目前尚未登陆,请选择【登陆】或【注册
首页->投票调查->简单多功能投票/调查系统源码>>Votes.aspx.cs>>代码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:简单多功能投票/调查系统源码


当前文件路径:Votes/Votes.aspx.cs 文件类型
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using System.Data.SqlClient; 12//该源码下载自www.51aspx.com(51aspx.com) 13 14public partial class Votes : System.Web.UI.Page 15{ 16 private int tid; 17 private string sHeader = ""; 18 protected void Page_Load(object sender, EventArgs e) 19 { 20 BindSubjectData(GetCurrentTopic()); 21 SubjectView.HeaderRow.Cells[0].Text = sHeader; 22 GetIsRepeat(); ///Label标签显示是否可以重复投票 23 } 24 25 private int GetCurrentTopic() 26 { 27 ITopics topic = new Topics(); 28 SqlDataReader dr = topic.GetCurrentTopic(); 29 if (dr.Read()) 30 { 31 sHeader = dr["t_name"].ToString(); 32 tid = Int32.Parse(dr["t_id"].ToString()); 33 } 34 dr.Close(); 35 return tid; 36 } 37 38 private void BindSubjectData(int tid) 39 { 40 ISubjects subject = new Subjects(); 41 SqlDataReader dr = subject.GetSubjectByTopic(tid); 42 SubjectView.DataSource = dr; 43 SubjectView.DataBind(); 44 dr.Close(); 45 } 46 47 protected void SubjectView_RowDataBound(object sender, GridViewRowEventArgs e) 48 { 49 Panel panel = (Panel)e.Row.FindControl("ItemPanel"); 50 if (panel != null) 51 { 52 if (SubjectView.DataKeys[e.Row.RowIndex].Values["s_mode"].ToString().ToLower() == "false") 53 { 54 RadioButtonList radiolist = new RadioButtonList(); 55 radiolist.ID = "radiolist"; ///或者radiolist.ID = "radio"; 56 BindItemDataByRadio(radiolist, Int32.Parse(SubjectView.DataKeys[e.Row.RowIndex].Values["s_id"].ToString())); 57 panel.Controls.Add(radiolist); 58 if (radiolist.Items.Count < 1) 59 panel.Controls.Add(new LiteralControl("<font color='red'>没有投票内容</font>")); 60 } 61 62 if (SubjectView.DataKeys[e.Row.RowIndex].Values["s_mode"].ToString().ToLower() == "true") 63 { 64 CheckBoxList checklist = new CheckBoxList(); 65 checklist.ID = "checklist"; 66 BindItemDataByCkeck(checklist, Int32.Parse(SubjectView.DataKeys[e.Row.RowIndex].Values["s_id"].ToString())); 67 panel.Controls.Add(checklist); 68 if (checklist.Items.Count < 1) 69 panel.Controls.Add(new LiteralControl("<font color='red'>没有投票内容</font>")); 70 } 71 } 72 } 73 74 private void BindItemDataByRadio(RadioButtonList radiolist, int sid) 75 { 76 IItems item = new Items(); 77 SqlDataReader dr = item.GetItemBySubject(sid); 78 radiolist.DataSource = dr; 79 radiolist.DataTextField = "i_name"; 80 radiolist.DataValueField = "i_id"; 81 radiolist.DataBind(); 82 dr.Close(); 83 } 84 85 private void BindItemDataByCkeck(CheckBoxList checklist, int sid) 86 { 87 IItems item = new Items(); 88 SqlDataReader dr = item.GetItemBySubject(sid); 89 checklist.DataSource = dr; 90 checklist.DataTextField = "i_name"; 91 checklist.DataValueField = "i_id"; 92 checklist.DataBind(); 93 dr.Close(); 94 } 95 96 protected void tp_Click(object sender, EventArgs e) 97 { 98 if (Session["IsRepeat"] != null && Session["vote"] != null) 99 { 100 lbl1.Text ="是否可以重复投:"+Session["IsRepeat"]; ///为了在前台显示 101 lbl2.Text = "是否已经投票:"+Session["vote"]; 102 if (Session["IsRepeat"].ToString().ToLower() == "false" && Session["vote"].ToString().ToLower() == "true") 103 { 104 Response.Write("<script>alert('禁止重复投票!');</script>"); 105 return; 106 } 107 } 108 109 IItems item = new Items(); 110 foreach (GridViewRow row in SubjectView.Rows) 111 { 112 Panel panel = (Panel)row.FindControl("ItemPanel"); 113 if (panel == null) continue; ///结束本次循环,执行下一次循环 114 foreach (Control control in panel.Controls) 115 { 116 if (control is RadioButtonList) 117 { 118 foreach (ListItem listitem in ((RadioButtonList)control).Items) 119 { 120 if (listitem.Selected == true) 121 { 122 item.AddItemCount(Int32.Parse(listitem.Value)); ///radiolist.DataValueField = "i_id"; 123 BindSubjectData(GetCurrentTopic()); 124 break; 125 } 126 } 127 } 128 129 if (control is CheckBoxList) 130 { 131 foreach(ListItem listitem in ((CheckBoxList)control).Items) 132 { 133 if (listitem.Selected == true) 134 { 135 item.AddItemCount(Int32.Parse(listitem.Value)); ///checklist.DataValueField = "i_id"; 136 BindSubjectData(GetCurrentTopic()); 137 ///书上在此加了break 错误!!! 138 } 139 } 140 } 141 } 142 } 143 Session["vote"] = "true"; 144 Response.Write("<script>alert('投票成功!');</script>"); 145 } 146 147 protected void GetIsRepeat() 148 { 149 IItems item = new Items(); 150 SqlDataReader dr=item.GetIsRepeat(); 151 if (dr.Read()) 152 { 153 Session["IsRepeat"] = dr["p_IsRepeat"]; ///保存是否可以重复投票纪录 154 155 if (dr["p_IsRepeat"].ToString().ToLower() =="true") 156 lbl.Text = "可以重复投票"; 157 else 158 lbl.Text = "不可以重复投票"; 159 } 160 dr.Close(); 161 } 162 163 protected void repeat_Click(object sender, EventArgs e) 164 { 165 IItems item = new Items(); 166 item.UpdateIsRepeat(RepeatList.SelectedValue); 167 Response.Write("<script>alert('修改是否可重复投票成功!');</script>"); 168 BindSubjectData(GetCurrentTopic()); 169 } 170} 171
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:简单多功能投票/调查系统源码

- 商务维基网源码

- 博易单用户博客V1.0Beta项目源码

- Asp.net大型B2B网站程序源码

- 某学校网络考试系统源码

- 银行模拟登陆系统源码

- 文献检索系统源码及毕业论文

- WebTextPane 在线编辑器

- 随风缘内容管理(JumbotCms!N..

51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号