温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:简单多功能投票/调查系统源码
当前文件路径:Votes/ShowVotesByPictures.aspx.cs

1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Data.SqlClient; 12
13
public partial class ShowVotesByPictures : System.Web.UI.Page 14
{ 15
private static string sHeader=""; 16
private int tid; 17
private string SumVoteCount = ""; 18
public class VotesList 19
{ 20
public string name; 21
public string count; 22
public string totalcount; 23
} 24
25
protected void Page_Load(object sender, EventArgs e) 26
{ 27
if (!Page.IsPostBack) BindSubjecsData(GetCurrentTopic()); 28
SubjectsView.HeaderRow.Cells[0].Text = sHeader; 29
} 30
31
private int GetCurrentTopic() 32
{ 33
ITopics topic = new Topics(); 34
SqlDataReader recu=topic.GetCurrentTopic(); 35
if (recu.Read()) 36
{ 37
tid=Int32.Parse(recu["t_id"].ToString()); 38
sHeader = recu["t_name"].ToString(); 39
} 40
return tid; 41
recu.Close(); 42
} 43
44
private void BindSubjecsData(int tid) 45
{ 46
ISubjects subject = new Subjects(); 47
SqlDataReader recu = subject.GetSubjectByTopic(tid); 48
SubjectsView.DataSource = recu; 49
SubjectsView.DataBind(); 50
recu.Close(); 51
} 52
53
54
protected void SubjectsView_RowDataBound(object sender, GridViewRowEventArgs e) 55
{ 56
GridView itemsview =(GridView)e.Row.FindControl("ItemsView"); 57
if (itemsview != null) 58
BindItemData(itemsview,Int32.Parse(SubjectsView.DataKeys[e.Row.RowIndex].Value.ToString())); 59
} 60
61
private void BindItemData(GridView itemsview, int sid) 62
{ 63
IItems item = new Items(); 64
SqlDataReader recu1=item.GetItemBySubject(sid); 65
SqlDataReader recu2 = item.GetSumItemsBySubject(sid); 66
67
if (recu2.Read())SumVoteCount = recu2["SumVoteCount"].ToString(); 68
69
ArrayList VoteArray = new ArrayList(); 70
while (recu1.Read()) 71
{ 72
VotesList votelist = new VotesList(); 73
votelist.name=recu1["i_name"].ToString(); 74
votelist.count = recu1["i_count"].ToString(); 75
votelist.totalcount = SumVoteCount; 76
VoteArray.Add(votelist); 77
} 78
itemsview.DataSource = VoteArray; 79
itemsview.DataBind(); 80
recu1.Close(); 81
recu2.Close(); 82
} 83
84
public int FormatCount(string count,string sumcount) 85
{ 86
if(count.Length<0||sumcount.Length<0)return (0); 87
int sumcount1 = Int32.Parse(sumcount); 88
int count1 = Int32.Parse(count); 89
return (count1*100/sumcount1); 90
} 91
92
public int FormatImage(int swidth) 93
{ 94
return swidth * 4; 95
} 96
97
///<asp:TemplateField FooterText="所占百分比"> 98
/// <ItemTemplate> 99
/// <asp:Image runat="server" ID="image" ImageUrl="~/vote.gif" Height="20" Width="<%#FormatImage(FormatCount(((VotesList)Container.DataItem).count, ((VotesList)Container.DataItem).totalcount))%>" /> 100
/// <%#FormatCount(((VotesList)Container.DataItem).count, ((VotesList)Container.DataItem).totalcount) %>% 101
/// </ItemTemplate> 102
/// </asp:TemplateField> 103
} 104





}
