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

  • Post author:
  • Post category:其他





  1. <


    table





    height


    =


    “286”




    cellSpacing


    =


    “0”




    cellPadding


    =


    “0”




    width


    =


    “1000”




    align


    =


    “center”




    bgColor


    =


    “#ffffff”



  2. border


    =


    “0”





    >





  3. <


    tbody


    >





  4. <


    tr


    >





  5. <


    td





    vAlign


    =


    “top”




    height


    =


    “286”





    >





  6. <


    div





    align


    =


    “left”





    >





  7. <


    table





    height


    =


    “32”




    cellSpacing


    =


    “0”




    cellPadding


    =


    “0”




    width


    =


    “968”




    align


    =


    “center”




    border


    =


    “0”





    >





  8. <


    tbody


    >





  9. <


    tr


    >





  10. <


    td


    >





  11. <


    div





    align


    =


    “center”





    >


    </


    div


    >





  12. <


    div





    align


    =


    “center”





    >


    <


    strong


    >


    <



    %=Title%



    >


    </


    strong


    >


    <


    br


    >





  13. </


    div


    >





  14. </


    td


    >





  15. </


    tr


    >





  16. </


    tbody


    >





  17. </


    table


    >





  18. <


    table





    cellSpacing


    =


    “0”




    cellPadding


    =


    “0”




    width


    =


    “915”




    align


    =


    “center”




    border


    =


    “0”





    >





  19. <


    tbody


    >





  20. <


    tr


    >





  21. <


    td





    background


    =


    “../../images/house4_07.jpg”




    height


    =


    “1”





    >


    <


    FONT





    face


    =


    “宋体”





    >


    </


    FONT


    >


    </


    td


    >





  22. </


    tr


    >





  23. <


    tr


    >





  24. <


    td


    >





  25. <


    table





    cellSpacing


    =


    “0”




    cellPadding


    =


    “0”




    width


    =


    “915”




    border


    =


    “0”





    >





  26. <


    asp:repeater





    id


    =


    “Repeater1”




    Runat


    =


    “server”





    >





  27. <


    ItemTemplate


    >





  28. <


    tr


    >





  29. <


    td


    >





  30. <



    %# DataBinder.Eval(Container, “DataItem.FVoteName”) %



    >





  31. <


    table





    width


    =


    “85%”




    align


    =


    “center”




    border


    =


    “1”




    bordercolor


    =


    “#D6E7FF”




    cellpadding


    =


    “0”




    cellspacing


    =


    “0”





    >





  32. <


    tr


    >





  33. <


    td


    >





  34. <


    asp:CheckBoxList





    id


    =


    “cb”




    Runat


    =


    “server”




    Visible


    =


    “False”





    >


    </


    asp:CheckBoxList


    >





  35. <


    asp:RadioButtonList





    ID


    =


    “rb”




    Runat


    =


    “server”




    Visible


    =


    “False”





    >


    </


    asp:RadioButtonList


    >





  36. <


    asp:TextBox





    ID


    =


    “tb”




    TextMode


    =


    “MultiLine”




    Columns


    =


    “40”




    Rows


    =


    “4”




    Runat


    =


    “server”




    Visible


    =


    “False”





    >


    </


    asp:TextBox


    >





  37. <


    input





    type


    =


    “hidden”




    id


    =


    “hb”




    runat


    =


    “server”





    />





  38. </


    td


    >





  39. </


    tr


    >





  40. </


    table


    >





  41. </


    td


    >





  42. </


    tr


    >





  43. </


    ItemTemplate


    >





  44. </


    asp:repeater


    >


    </


    table


    >





  45. </


    td


    >





  46. </


    tr


    >





  47. <


    tr


    >





  48. <


    td





    align


    =


    “center”





    >


    <


    asp:button





    id


    =


    “btnAdd”




    runat


    =


    “server”




    Text


    =


    “提交”





    >


    </


    asp:button


    >


    </


    td


    >





  49. </


    tr


    >





  50. </


    tbody


    >





  51. </


    table


    >





  52. </


    div


    >





  53. <


    div





    align


    =


    “right”





    >


    </


    div


    >





  54. </


    td


    >





  55. </


    tr


    >





  56. </


    tbody


    >





  57. </


    table


    >


<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="../../images/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>

																	<%# DataBinder.Eval(Container, "DataItem.FVoteName") %>

																	<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. public

    Seaskyer.Modules.Utils.DBClass db =

    new

    Seaskyer.Modules.Utils.DBClass();

  3. protected

    System.Web.UI.WebControls.Button btnAdd;

  4. public


    string

    Title;

  5. //public string cid;

  6. private


    void

    Page_Load(

    object

    sender, System.EventArgs e)
  7. {

  8. if

    (!Page.IsPostBack)
  9. {

  10. string

    cid =

    “”

    ;

  11. if

    (db.q(

    “id”

    )!=

    “”

    )
  12. {
  13. cid=db.q(

    “id”

    );
  14. }
  15. Title = db.getSingleValue(

    “cms_VotePro”

    ,

    “FProName”

    ,

    “FID”

    ,cid);
  16. BindRep();
  17. }
  18. }

  19. /// <summary>

  20. /// 绑定Repeater控件,显示调查中的大类

  21. /// </summary>

  22. public


    void

    BindRep()
  23. {

  24. string

    strsql =

    “select * from cms_vote where FProID='”

    +db.q(

    “id”

    )+

    “‘”

    ;
  25. db.dp.CommandText = strsql;
  26. DataTable dt = db.dp.DataTableSQL();

  27. if

    (dt.Rows.Count>0)
  28. {

  29. this

    .Repeater1.DataSource = dt;

  30. this

    .Repeater1.DataBind();
  31. }
  32. }


  33. #region Web 窗体设计器生成的代码

  34. override


    protected


    void

    OnInit(EventArgs e)
  35. {

  36. //

  37. // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。

  38. //
  39. InitializeComponent();

  40. base

    .OnInit(e);
  41. }

  42. /// <summary>

  43. /// 设计器支持所需的方法 – 不要使用代码编辑器修改

  44. /// 此方法的内容。

  45. /// </summary>

  46. private


    void

    InitializeComponent()
  47. {

  48. this

    .Repeater1.ItemDataBound +=

    new

    System.Web.UI.WebControls.RepeaterItemEventHandler(

    this

    .Repeater1_ItemDataBound);

  49. this

    .btnAdd.Click +=

    new

    System.EventHandler(

    this

    .btnAdd_Click);

  50. this

    .Load +=

    new

    System.EventHandler(

    this

    .Page_Load);
  51. }

  52. #endregion

  53. private


    void

    Repeater1_ItemDataBound(

    object

    sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
  54. {
  55. CheckBoxList cb    = (CheckBoxList)e.Item.FindControl(

    “cb”

    );
  56. RadioButtonList rb = (RadioButtonList)e.Item.FindControl(

    “rb”

    );
  57. TextBox tb         = (TextBox)e.Item.FindControl(

    “tb”

    );
  58. System.Web.UI.HtmlControls.HtmlInputHidden hb = (HtmlInputHidden)e.Item.FindControl(

    “hb”

    );
  59. DataRowView rowv = (DataRowView)e.Item.DataItem;

  60. //提取分类ID

  61. string

    Fid  = rowv[

    “FVoteId”

    ].ToString();

  62. string

    type = rowv[

    “FType”

    ].ToString();

  63. string

    strsql =

    “select * from cms_VoteItem where FVoteId='”

    +Fid+

    “‘”

    ;

  64. //Response.Write(“<script>alert(‘”+strsql+”‘);</script>”);
  65. db.dp.CommandText = strsql;
  66. DataTable dt = db.dp.DataTableSQL();

  67. switch

    (Convert.ToInt32(type))
  68. {

  69. case

    1:
  70. rb.Visible =

    true

    ;
  71. cb.Visible =

    false

    ;
  72. tb.Visible =

    false

    ;
  73. rb.DataSource = dt;
  74. rb.DataTextField =

    “FItemName”

    ;
  75. rb.DataValueField =

    “FID”

    ;
  76. rb.DataBind();

  77. break

    ;

  78. case

    2:
  79. rb.Visible =

    false

    ;
  80. cb.Visible =

    true

    ;
  81. tb.Visible =

    false

    ;
  82. cb.DataSource = dt;
  83. cb.DataTextField =

    “FItemName”

    ;
  84. cb.DataValueField =

    “FID”

    ;
  85. cb.DataBind();

  86. break

    ;

  87. case

    3:
  88. tb.Visible =

    true

    ;
  89. rb.Visible =

    false

    ;
  90. cb.Visible =

    false

    ;

  91. break

    ;
  92. }
  93. }

  94. private


    void

    btnAdd_Click(

    object

    sender, System.EventArgs e)
  95. {

  96. string

    cb =

    “”

    ;

    //复选框

  97. string

    rb =

    “”

    ;

    //单选框

  98. string

    tb =

    “”

    ;

    //如果有文本框

  99. foreach

    (RepeaterItem   item

    in


    this

    .Repeater1.Items)
  100. {
  101. CheckBoxList cb1    = (CheckBoxList)item.FindControl(

    “cb”

    );
  102. RadioButtonList rb1 = (RadioButtonList)item.FindControl(

    “rb”

    );
  103. TextBox tb1         = (TextBox)item.FindControl(

    “tb”

    );

  104. //CheckBox cb =   (CheckBox)item.FindControl(“CheckBoxRole”);

  105. if

    (cb1.Visible==

    true

    )
  106. {

  107. for

    (

    int

    i=0;i<cb1.Items.Count;i++)
  108. {

  109. if

    (cb1.Items[i].Selected==

    true

    )
  110. {
  111. cb +=

    “‘”

    +cb1.Items[i].Value+

    “‘”

    +

    “,”

    ;
  112. }
  113. }
  114. }

  115. if

    (rb1.Visible==

    true

    )
  116. {

  117. for

    (

    int

    i=0;i<rb1.Items.Count;i++)
  118. {

  119. if

    (rb1.Items[i].Selected==

    true

    )
  120. {
  121. rb =

    “‘”

    +rb1.Items[i].Value+

    “‘”

    ;
  122. }
  123. }
  124. }

  125. if

    (tb1.Visible==

    true

    )
  126. {
  127. tb = tb1.Text +

    “|”

    ;
  128. }
  129. }

  130. string

    id =

    “”

    ;

  131. if

    (cb.Trim()!=

    “”

    )
  132. {
  133. cb = cb.Substring(0,cb.Length-1);
  134. id = cb;
  135. }

  136. if

    (rb.Trim()!=

    “”

    )
  137. {

  138. if

    (id.Trim()!=

    “”

    )
  139. {
  140. id +=

    “,”

    + rb;
  141. }

  142. else
  143. {
  144. id += rb;
  145. }
  146. }

  147. //id = cb + rb;

  148. if

    (id.Trim()==

    “”

    )
  149. {
  150. Response.Write(

    “<script>alert(‘你没有进行选择!’);history.go(-1);</script>”

    );
  151. }

  152. string

    strsql =

    “update cms_VoteItem set FItemNum=FItemNum+1 where FID in (”

    +id+

    “)”

    ;
  153. db.dp.CommandText = strsql;
  154. db.dp.ExecuteNonQuery();
  155. Response.Write(

    “<script>alert(‘投票结束!’);location.href=’VoteView.aspx?id=”

    +db.q(

    “id”

    )+

    “‘;</script>”

    );

  156. //          Response.Write(id);
  157. }</PRE>

  
  
  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.         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.   
  19.         {   
  20.   
  21.             if(!Page.IsPostBack)   
  22.   
  23.             {   
  24.   
  25.                 string cid = "";   
  26.   
  27.                 if(db.q("id")!="")   
  28.   
  29.                 {   
  30.   
  31.                     cid=db.q("id");   
  32.   
  33.                 }   
  34.   
  35.   
  36.   
  37.   
  38.   
  39.                 Title = db.getSingleValue("cms_VotePro","FProName","FID",cid);   
  40.   
  41.   
  42.   
  43.                 BindRep();   
  44.   
  45.             }   
  46.   
  47.         }   
  48.   
  49.   
  50.   
  51.         /// <summary>   
  52.   
  53.         /// 绑定Repeater控件,显示调查中的大类   
  54.   
  55.         /// </summary>   
  56.   
  57.         public void BindRep()   
  58.   
  59.         {   
  60.   
  61.             string strsql = "select * from cms_vote where FProID='"+db.q("id")+"'";   
  62.   
  63.             db.dp.CommandText = strsql;   
  64.   
  65.             DataTable dt = db.dp.DataTableSQL();   
  66.   
  67.             if(dt.Rows.Count>0)   
  68.   
  69.             {   
  70.   
  71.                 this.Repeater1.DataSource = dt;   
  72.   
  73.                 this.Repeater1.DataBind();   
  74.   
  75.             }   
  76.   
  77.         }  
  78.  
  79.           
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.         #region Web 窗体设计器生成的代码   
  88.   
  89.         override protected void OnInit(EventArgs e)   
  90.   
  91.         {   
  92.   
  93.             //   
  94.   
  95.             // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。   
  96.   
  97.             //   
  98.   
  99.             InitializeComponent();   
  100.   
  101.             base.OnInit(e);   
  102.   
  103.         }   
  104.   
  105.            
  106.   
  107.         /// <summary>   
  108.   
  109.         /// 设计器支持所需的方法 - 不要使用代码编辑器修改   
  110.   
  111.         /// 此方法的内容。   
  112.   
  113.         /// </summary>   
  114.   
  115.         private void InitializeComponent()   
  116.   
  117.         {       
  118.   
  119.             this.Repeater1.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(this.Repeater1_ItemDataBound);   
  120.   
  121.             this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);   
  122.   
  123.             this.Load += new System.EventHandler(this.Page_Load);   
  124.   
  125.   
  126.   
  127.         }  
  128.  
  129.         #endregion   
  130.   
  131.   
  132.   
  133.         private void Repeater1_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)   
  134.   
  135.         {   
  136.   
  137.             CheckBoxList cb    = (CheckBoxList)e.Item.FindControl("cb");   
  138.   
  139.             RadioButtonList rb = (RadioButtonList)e.Item.FindControl("rb");   
  140.   
  141.             TextBox tb         = (TextBox)e.Item.FindControl("tb");   
  142.   
  143.             System.Web.UI.HtmlControls.HtmlInputHidden hb = (HtmlInputHidden)e.Item.FindControl("hb");   
  144.   
  145.             DataRowView rowv = (DataRowView)e.Item.DataItem;   
  146.   
  147.             //提取分类ID   
  148.   
  149.             string Fid  = rowv["FVoteId"].ToString();   
  150.   
  151.             string type = rowv["FType"].ToString();   
  152.   
  153.   
  154.   
  155.             string strsql = "select * from cms_VoteItem where FVoteId='"+Fid+"'";   
  156.   
  157.   
  158.   
  159.             //Response.Write("<script>alert('"+strsql+"');</script>");   
  160.   
  161.             db.dp.CommandText = strsql;   
  162.   
  163.             DataTable dt = db.dp.DataTableSQL();   
  164.   
  165.                
  166.   
  167.             switch(Convert.ToInt32(type))   
  168.   
  169.             {   
  170.   
  171.                 case 1:   
  172.   
  173.                     rb.Visible = true;   
  174.   
  175.                     cb.Visible = false;   
  176.   
  177.                     tb.Visible = false;   
  178.   
  179.                     rb.DataSource = dt;   
  180.   
  181.                     rb.DataTextField = "FItemName";   
  182.   
  183.                     rb.DataValueField = "FID";   
  184.   
  185.                     rb.DataBind();   
  186.   
  187.                     break;   
  188.   
  189.                 case 2:   
  190.   
  191.                     rb.Visible = false;   
  192.   
  193.                     cb.Visible = true;   
  194.   
  195.                     tb.Visible = false;   
  196.   
  197.                     cb.DataSource = dt;   
  198.   
  199.                     cb.DataTextField = "FItemName";   
  200.   
  201.                     cb.DataValueField = "FID";   
  202.   
  203.                     cb.DataBind();   
  204.   
  205.                     break;   
  206.   
  207.                 case 3:   
  208.   
  209.                     tb.Visible = true;   
  210.   
  211.                        
  212.   
  213.                     rb.Visible = false;   
  214.   
  215.                     cb.Visible = false;   
  216.   
  217.                     break;   
  218.   
  219.             }   
  220.   
  221.         }   
  222.   
  223.   
  224.   
  225.         private void btnAdd_Click(object sender, System.EventArgs e)   
  226.   
  227.         {   
  228.   
  229.             string cb = "";//复选框   
  230.   
  231.             string rb = "";//单选框   
  232.   
  233.             string tb = "";//如果有文本框   
  234.   
  235.             foreach   (RepeaterItem   item   in   this.Repeater1.Items)       
  236.   
  237.             {     
  238.   
  239.   
  240.   
  241.                 CheckBoxList cb1    = (CheckBoxList)item.FindControl("cb");   
  242.   
  243.                 RadioButtonList rb1 = (RadioButtonList)item.FindControl("rb");   
  244.   
  245.                 TextBox tb1         = (TextBox)item.FindControl("tb");   
  246.   
  247.   
  248.   
  249.                 //CheckBox cb =   (CheckBox)item.FindControl("CheckBoxRole");     
  250.   
  251.                 if(cb1.Visible==true)   
  252.   
  253.                 {   
  254.   
  255.                     for(int i=0;i<cb1.Items.Count;i++)   
  256.   
  257.                     {   
  258.   
  259.                         if(cb1.Items[i].Selected==true)   
  260.   
  261.                         {   
  262.   
  263.                             cb += "'"+cb1.Items[i].Value+"'" + ",";   
  264.   
  265.                         }   
  266.   
  267.                     }   
  268.   
  269.                 }   
  270.   
  271.      
  272.   
  273.                 if(rb1.Visible==true)   
  274.   
  275.                 {   
  276.   
  277.                     for(int i=0;i<rb1.Items.Count;i++)   
  278.   
  279.                     {   
  280.   
  281.                         if(rb1.Items[i].Selected==true)   
  282.   
  283.                         {   
  284.   
  285.                             rb = "'"+rb1.Items[i].Value+"'";   
  286.   
  287.                         }   
  288.   
  289.                     }   
  290.   
  291.                 }   
  292.   
  293.   
  294.   
  295.                 if(tb1.Visible==true)   
  296.   
  297.                 {   
  298.   
  299.                     tb = tb1.Text + "|";   
  300.   
  301.                 }   
  302.   
  303.             }   
  304.   
  305.   
  306.   
  307.             string id = "";   
  308.   
  309.   
  310.   
  311.             if(cb.Trim()!="")   
  312.   
  313.             {   
  314.   
  315.                 cb = cb.Substring(0,cb.Length-1);   
  316.   
  317.                 id = cb;   
  318.   
  319.             }   
  320.   
  321.   
  322.   
  323.             if(rb.Trim()!="")   
  324.   
  325.             {   
  326.   
  327.                 if(id.Trim()!="")   
  328.   
  329.                 {   
  330.   
  331.                     id += "," + rb;   
  332.   
  333.                 }   
  334.   
  335.                 else  
  336.   
  337.                 {   
  338.   
  339.                     id += rb;   
  340.   
  341.                 }   
  342.   
  343.             }   
  344.   
  345.             //id = cb + rb;   
  346.   
  347.   
  348.   
  349.             if(id.Trim()=="")   
  350.   
  351.             {   
  352.   
  353.                 Response.Write("<script>alert('你没有进行选择!');history.go(-1);</script>");   
  354.   
  355.             }   
  356.   
  357.             string strsql = "update cms_VoteItem set FItemNum=FItemNum+1 where FID in ("+id+")";   
  358.   
  359.             db.dp.CommandText = strsql;   
  360.   
  361.             db.dp.ExecuteNonQuery();   
  362.   
  363.             Response.Write("<script>alert('投票结束!');location.href='VoteView.aspx?id="+db.q("id")+"';</script>");   
  364.   
  365. //          Response.Write(id);   
  366.   
  367.         }  

3,显示投票结果前台




  1. <


    table





    height


    =


    “286”




    cellSpacing


    =


    “0”




    cellPadding


    =


    “0”




    width


    =


    “1000”




    align


    =


    “center”




    bgColor


    =


    “#ffffff”



  2. border


    =


    “0”





    >





  3. <


    tbody


    >





  4. <


    tr


    >





  5. <


    td





    vAlign


    =


    “top”




    height


    =


    “286”





    >





  6. <


    div





    align


    =


    “left”





    >





  7. <


    table





    height


    =


    “32”




    cellSpacing


    =


    “0”




    cellPadding


    =


    “0”




    width


    =


    “968”




    align


    =


    “center”




    border


    =


    “0”





    >





  8. <


    tbody


    >





  9. <


    tr


    >





  10. <


    td


    >





  11. <


    div





    align


    =


    “center”





    >


    </


    div


    >





  12. <


    div





    align


    =


    “center”





    >


    <


    strong


    >


    <



    %=Title%



    >


    </


    strong


    >


    <


    br


    >





  13. </


    div


    >





  14. </


    td


    >





  15. </


    tr


    >





  16. </


    tbody


    >





  17. </


    table


    >





  18. <


    table





    cellSpacing


    =


    “0”




    cellPadding


    =


    “0”




    width


    =


    “915”




    align


    =


    “center”




    border


    =


    “0”





    >





  19. <


    tbody


    >





  20. <


    tr


    >





  21. <


    td





    background


    =


    “../../images/house4_07.jpg”




    height


    =


    “1”





    >


    <


    FONT





    face


    =


    “宋体”





    >


    </


    FONT


    >


    </


    td


    >





  22. </


    tr


    >





  23. <


    tr


    >





  24. <


    td


    >





  25. <


    table





    cellSpacing


    =


    “0”




    cellPadding


    =


    “0”




    width


    =


    “915”




    border


    =


    “0”





    >





  26. <


    asp:repeater





    id


    =


    “Repeater1”




    Runat


    =


    “server”





    >





  27. <


    ItemTemplate


    >





  28. <


    tr


    >





  29. <


    td


    >





  30. <



    %# DataBinder.Eval(Container, “DataItem.FVoteName”) %



    >





  31. <


    asp:Repeater





    ID


    =


    “rep”




    Runat


    =


    “server”





    >





  32. <


    ItemTemplate


    >





  33. <


    table





    width


    =


    “85%”




    align


    =


    “center”




    border


    =


    “1”




    bordercolor


    =


    “#D6E7FF”




    cellpadding


    =


    “0”




    cellspacing


    =


    “0”





    >





  34. <


    tr


    >





  35. <


    td





    width


    =


    “10%”





    >


  36. 选项:



  37. </


    td





    width


    =


    “20%”





    >





  38. <


    td


    >


    <



    %# DataBinder.Eval(Container, “DataItem.FItemName”) %



    >


    </


    td


    >





  39. <


    td





    width


    =


    “10%”





    >



    票数:



    </


    td


    >





  40. <


    td





    width


    =


    “10%”





    >


    <



    %# DataBinder.Eval(Container, “DataItem.FItemNum”) %



    >


    </


    td


    >





  41. <


    td





    width


    =


    “10%”





    >



    百分比:



    </


    td


    >





  42. <


    td





    width


    =


    “40%”





    >


    <


    img





    src


    =


    “images/654.gif”




    height


    =


    “5”




    width


    =”



    <



    %# IsViews(DataBinder.Eval(Container, ”


    DataItem


    .FVoteId”).ToString(),DataBinder.Eval(Container, “DataItem.FItemNum”).ToString()) %



    >







    >


    <



    %# IsView(DataBinder.Eval(Container, “DataItem.FVoteId”).ToString(),DataBinder.Eval(Container, “DataItem.FItemNum”).ToString()) %



    >


    </


    td


    >





  43. </


    tr


    >





  44. </


    table


    >





  45. </


    ItemTemplate


    >





  46. </


    asp:Repeater


    >





  47. </


    td


    >





  48. </


    tr


    >





  49. </


    ItemTemplate


    >





  50. </


    asp:repeater


    >


    </


    table


    >





  51. </


    td


    >





  52. </


    tr


    >





  53. <


    tr


    >





  54. <


    td





    align


    =


    “center”





    >


    </


    td


    >





  55. </


    tr


    >





  56. </


    tbody


    >





  57. </


    table


    >





  58. </


    div


    >





  59. <


    div





    align


    =


    “right”





    >


    <


    FONT





    face


    =


    “宋体”





    >


    </


    FONT


    >


    </


    div


    >





  60. </


    td


    >





  61. </


    tr


    >





  62. </


    tbody


    >





  63. </


    table


    >


<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="../../images/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>

																	<%# DataBinder.Eval(Container, "DataItem.FVoteName") %>

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

																		<ItemTemplate>

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

																				<tr>

																					<td width="10%">

																						选项:

																					</td width="20%">

																					<td><%# DataBinder.Eval(Container, "DataItem.FItemName") %></td>

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

																					<td width="10%"><%# DataBinder.Eval(Container, "DataItem.FItemNum") %></td>

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

																					<td width="40%"><img src="images/654.gif" height="5" width="<%# IsViews(DataBinder.Eval(Container, "DataItem.FVoteId").ToString(),DataBinder.Eval(Container, "DataItem.FItemNum").ToString()) %>"><%# IsView(DataBinder.Eval(Container, "DataItem.FVoteId").ToString(),DataBinder.Eval(Container, "DataItem.FItemNum").ToString()) %></td>

																				</tr>

																			</table>

																		</ItemTemplate>

																	</asp:Repeater>

																</td>

															</tr>

														</ItemTemplate>

													</asp:repeater></table>

											</td>

										</tr>

										<tr>

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

										</tr>

									</tbody>

								</table>

							</div>

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

						</td>

					</tr>

				</tbody>

			</table>

4,后台代码


  1. protected

    System.Web.UI.WebControls.Repeater Repeater1;

  2. public

    Seaskyer.Modules.Utils.DBClass db =

    new

    Seaskyer.Modules.Utils.DBClass();

  3. public


    string

    Title;

  4. //public string cid;

  5. private


    void

    Page_Load(

    object

    sender, System.EventArgs e)
  6. {

  7. if

    (!Page.IsPostBack)
  8. {

  9. string

    cid =

    “”

    ;

  10. if

    (db.q(

    “id”

    )!=

    “”

    )
  11. {
  12. cid=db.q(

    “id”

    );
  13. }
  14. Title = db.getSingleValue(

    “cms_VotePro”

    ,

    “FProName”

    ,

    “FID”

    ,cid);
  15. BindRep();
  16. }
  17. }

  18. /// <summary>

  19. /// 绑定Repeater控件,显示调查中的大类

  20. /// </summary>

  21. public


    void

    BindRep()
  22. {

  23. string

    strsql =

    “select * from cms_vote where FProID='”

    +db.q(

    “id”

    )+

    “‘”

    ;
  24. db.dp.CommandText = strsql;
  25. DataTable dt = db.dp.DataTableSQL();

  26. if

    (dt.Rows.Count>0)
  27. {

  28. this

    .Repeater1.DataSource = dt;

  29. this

    .Repeater1.DataBind();
  30. }
  31. }

  32. #region Web 窗体设计器生成的代码

  33. override


    protected


    void

    OnInit(EventArgs e)
  34. {

  35. //

  36. // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。

  37. //
  38. InitializeComponent();

  39. base

    .OnInit(e);
  40. }

  41. /// <summary>

  42. /// 设计器支持所需的方法 – 不要使用代码编辑器修改

  43. /// 此方法的内容。

  44. /// </summary>

  45. private


    void

    InitializeComponent()
  46. {

  47. this

    .Repeater1.ItemDataBound +=

    new

    System.Web.UI.WebControls.RepeaterItemEventHandler(

    this

    .Repeater1_ItemDataBound);

  48. this

    .Load +=

    new

    System.EventHandler(

    this

    .Page_Load);
  49. }

  50. #endregion

  51. private


    void

    Repeater1_ItemDataBound(

    object

    sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
  52. {
  53. Repeater rep  = (Repeater)e.Item.FindControl(

    “rep”

    );
  54. DataRowView rowv = (DataRowView)e.Item.DataItem;

  55. //提取分类ID

  56. string

    Fid  = rowv[

    “FVoteId”

    ].ToString();

  57. string

    strsql =

    “select * from cms_VoteItem where FVoteId='”

    +Fid+

    “‘”

    ;

  58. //Response.Write(“<script>alert(‘”+strsql+”‘);</script>”);
  59. db.dp.CommandText = strsql;
  60. DataTable dt = db.dp.DataTableSQL();
  61. rep.DataSource = dt;
  62. rep.DataBind();
  63. }

  64. public


    string

    IsView(

    string

    cid,

    string

    num)
  65. {

  66. string

    strsql =

    “select sum(FItemNum) from cms_VoteItem where FVoteId='”

    +cid+

    “‘”

    ;
  67. db.dp.CommandText = strsql;
  68. DataTable dt = db.dp.DataTableSQL();

  69. double

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

  70. if

    (num==

    “0”

    )

  71. return


    “0%”

    ;

  72. else

  73. return

    (Convert.ToDouble(num)/Sums).ToString(

    “P”

    );
  74. }

  75. public


    string

    IsViews(

    string

    cid,

    string

    num)
  76. {

  77. string

    strsql =

    “select sum(FItemNum) from cms_VoteItem where FVoteId='”

    +cid+

    “‘”

    ;
  78. db.dp.CommandText = strsql;
  79. DataTable dt = db.dp.DataTableSQL();

  80. double

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

  81. if

    (num==

    “0”

    )

  82. return


    “0%”

    ;

  83. else

  84. return

    (Convert.ToDouble(num)/Sums*300).ToString();
  85. }
protected System.Web.UI.WebControls.Repeater Repeater1;



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



		public string Title;



		//public string cid;

	

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

		{

			if(!Page.IsPostBack)

			{

				string cid = "";

				if(db.q("id")!="")

				{

					cid=db.q("id");

				}



				Title = db.getSingleValue("cms_VotePro","FProName","FID",cid);



				BindRep();

			}

		}



		/// <summary>

		/// 绑定Repeater控件,显示调查中的大类

		/// </summary>

		public void BindRep()

		{

			string strsql = "select * from cms_vote where FProID='"+db.q("id")+"'";

			db.dp.CommandText = strsql;

			DataTable dt = db.dp.DataTableSQL();

			if(dt.Rows.Count>0)

			{

				this.Repeater1.DataSource = dt;

				this.Repeater1.DataBind();

			}

		}



		#region Web 窗体设计器生成的代码

		override protected void OnInit(EventArgs e)

		{

			//

			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。

			//

			InitializeComponent();

			base.OnInit(e);

		}

		

		/// <summary>

		/// 设计器支持所需的方法 - 不要使用代码编辑器修改

		/// 此方法的内容。

		/// </summary>

		private void InitializeComponent()

		{    

			this.Repeater1.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(this.Repeater1_ItemDataBound);

			this.Load += new System.EventHandler(this.Page_Load);



		}

		#endregion



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

		{

		    Repeater rep  = (Repeater)e.Item.FindControl("rep");



			DataRowView rowv = (DataRowView)e.Item.DataItem;

			//提取分类ID

			string Fid  = rowv["FVoteId"].ToString();



			string strsql = "select * from cms_VoteItem where FVoteId='"+Fid+"'";



			



			//Response.Write("<script>alert('"+strsql+"');</script>");

			db.dp.CommandText = strsql;

			DataTable dt = db.dp.DataTableSQL();



			rep.DataSource = dt;

			rep.DataBind();

		}





		public string IsView(string cid,string num)

		{

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

			db.dp.CommandText = strsql;

			DataTable dt = db.dp.DataTableSQL();

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

			if(num=="0")

				return "0%";

			else

			    return (Convert.ToDouble(num)/Sums).ToString("P");

		}



		public string IsViews(string cid,string num)

		{

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

			db.dp.CommandText = strsql;

			DataTable dt = db.dp.DataTableSQL();

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

			if(num=="0")

				return "0%";

			else

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

		}

其中的表cms_VotePro是记录复式的主标题 cms_vote是记录投票项 cms_VoteItem是最后的小项了