您的位置:首页 > 编程语言 > ASP

asp.net中repeater嵌套CheckBoxList,RadioButtonList来完成投票

2008-07-11 17:31 399 查看
我们在做复式投票的时候。会遇到标题和选项嵌套的样子,下面我把我的代码放上来。
1,投票选择前台页面

# <table height="286" cellSpacing="0" cellPadding="0" width="1000" align="center" bgColor="#ffffff"

#

# border="0">

#

# <tbody>

#

# <tr>

#

# <td vAlign="top" height="286">

#

# <div align="left">

<table height="32" cellSpacing="0" cellPadding="0" width="968" align="center" border="0">

<tbody>

<tr>

<td>

<div align="center"></div>

#

# <div align="center"><strong><%=Title%></strong><br>

#

# </div>

#

# </td>

#

# </tr>

#

# </tbody>

#

# </table>

#

# <table cellSpacing="0" cellPadding="0" width="915" align="center" border="0">

#

# <tbody>

#

# <tr>

#

# <td background="http://images.cnblogs.com/house4_07.jpg" height="1"><FONT face="宋体"></FONT></td>

#

# </tr>

#

# <tr>

#

# <td>

#

# <table cellSpacing="0" cellPadding="0" width="915" border="0">

#

# <asp:repeater id="Repeater1" Runat="server">

#

# <ItemTemplate>

#

# <tr>

#

# <td>

#

#

# <table width="85%" align="center" border="1" bordercolor="#D6E7FF" cellpadding="0" cellspacing="0">

#

# <tr>

#

# <td>

#

# <asp:CheckBoxList id="cb" Runat="server" Visible="False"></asp:CheckBoxList>

#

# <asp:RadioButtonList ID="rb" Runat="server" Visible="False"></asp:RadioButtonList>

#

# <asp:TextBox ID="tb" TextMode="MultiLine" Columns="40" Rows="4" Runat="server" Visible="False"></asp:TextBox>

#

# <input type="hidden" id="hb" runat="server" />

#

# </td>

#

# </tr>

#

# </table>

#

# </td>

#

# </tr>

#

# </ItemTemplate>

#

# </asp:repeater></table>

#

# </td>

#

# </tr>

#

# <tr>

#

# <td align="center"><asp:button id="btnAdd" runat="server" Text="提交"></asp:button></td>

#

# </tr>

#

# </tbody>

#

# </table>

#

# </div>

#

# <div align="right"></div>

#

# </td>

#

# </tr>

#

# </tbody>

#

# </table>
2,后台代码

1. <pre class="csharp" name="code">protected System.Web.UI.WebControls.Repeater Repeater1;

2.

3.

4.

5. public Seaskyer.Modules.Utils.DBClass db = new Seaskyer.Modules.Utils.DBClass();

6.

7. protected System.Web.UI.WebControls.Button btnAdd;

8.

9.

10.

11. public string Title;

12.

13. //public string cid;

14.

15.

16.

17. private void Page_Load(object sender, System.EventArgs e)

18.

48.

49.

50.

52.

54.

56.

57. public void BindRep()

58.

78.

79.

80.

81.

82.

83.

84.

85.

86.

130.

131.

132.

133. private void Repeater1_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)

134.

222.

223.

224.

225. private void btnAdd_Click(object sender, System.EventArgs e)

226.

1. <table height="286" cellSpacing="0" cellPadding="0" width="1000" align="center" bgColor="#ffffff"

2.

3. border="0">

4.

5. <tbody>

6.

7. <tr>

8.

9. <td vAlign="top" height="286">

10.

11. <div align="left">

12.

13. <table height="32" cellSpacing="0" cellPadding="0" width="968" align="center" border="0">

14.

15. <tbody>

16.

17. <tr>

18.

19. <td>

20.

21. <div align="center"></div>

22.

23. <div align="center"><strong><%=Title%></strong><br>

24.

25. </div>

26.

27. </td>

28.

29. </tr>

30.

31. </tbody>

32.

33. </table>

34.

35. <table cellSpacing="0" cellPadding="0" width="915" align="center" border="0">

36.

37. <tbody>

38.

39. <tr>

40.

41. <td background="http://images.cnblogs.com/house4_07.jpg" height="1"><FONT face="宋体"></FONT></td>

42.

43. </tr>

44.

45. <tr>

46.

47. <td>

48.

49. <table cellSpacing="0" cellPadding="0" width="915" border="0">

50.

51. <asp:repeater id="Repeater1" Runat="server">

52.

53. <ItemTemplate>

54.

55. <tr>

56.

57. <td>

58.

60.

61. <asp:Repeater ID="rep" Runat="server">

62.

63. <ItemTemplate>

64.

65. <table width="85%" align="center" border="1" bordercolor="#D6E7FF" cellpadding="0" cellspacing="0">

66.

67. <tr>

68.

69. <td width="10%">

70.

71. 选项:

72.

73. </td width="20%">

74.

76.

77. <td width="10%">票数:</td>

78.

80.

81. <td width="10%">百分比:</td>

82.

84.

85. </tr>

86.

87. </table>

88.

89. </ItemTemplate>

90.

91. </asp:Repeater>

92.

93. </td>

94.

95. </tr>

96.

97. </ItemTemplate>

98.

99. </asp:repeater></table>

100.

101. </td>

102.

103. </tr>

104.

105. <tr>

106.

107. <td align="center"></td>

108.

109. </tr>

110.

111. </tbody>

112.

113. </table>

114.

115. </div>

116.

117. <div align="right"><FONT face="宋体"></FONT></div>

118.

119. </td>

120.

121. </tr>

122.

123. </tbody>

124.

125. </table>

4,后台代码

1. protected System.Web.UI.WebControls.Repeater Repeater1;

2.

3.

4.

5. public Seaskyer.Modules.Utils.DBClass db = new Seaskyer.Modules.Utils.DBClass();

6.

7.

8.

9. public string Title;

10.

11.

12.

13. //public string cid;

14.

15.

16.

17. private void Page_Load(object sender, System.EventArgs e)

18.

46.

47.

48.

50.

52.

54.

55. public void BindRep()

56.

76.

77.

78.

120.

121.

122.

123. private void Repeater1_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)

124.

160.

161.

162.

163.

164.

165. public string IsView(string cid,string num)

166.

186.

187.

188.

189. public string IsViews(string cid,string num)

190.

191. {

192.

193. string strsql = "select sum(FItemNum) from cms_VoteItem where FVoteId='"+cid+"'";

194.

195. db.dp.CommandText = strsql;

196.

197. DataTable dt = db.dp.DataTableSQL();

198.

199. double Sums = Convert.ToInt32(dt.Rows[0][0].ToString());

200.

201. if(num=="0")

202.

203. return "0%";

204.

205. else

206.

207. return (Convert.ToDouble(num)/Sums*300).ToString();

208.

209. }

其中的表cms_VotePro是记录复式的主标题
cms_vote是记录投票项
cms_VoteItem是最后的小项了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐