【问题标题】:checkboxes in repeater中继器中的复选框
【发布时间】:2011-07-23 02:47:53
【问题描述】:

我在每个项目中都有一个中继器和一个未绑定的复选框。 我想为检查的项目做点什么。 但问题就在这里! 当我点击中继器外的按钮时,我的页面只刷新,没有任何反应。

这些是我的代码:

<asp:Repeater ID="Repeater1" runat="server" >    
           <ItemTemplate>
               <asp:CheckBox ID="ChBox" runat="server" />
               <asp:Label ID="rptBody" runat="server" Text='<%#Eval("subject") %>
               <hr />
           </ItemTemplate>
    </asp:Repeater>
    <asp:Button ID="btnDelete" runat="server" Text="Delete" Width="90px"     onclick="btnDelete_Click" />

cs文件中的代码:

  protected void btnDelete_Click(object sender, EventArgs e)
        {
             foreach (RepeaterItem item in Repeater1.Items)
            {
                CheckBox ch = item.FindControl("ChBox") as CheckBox;
               if (ch.Checked)
                {
                   ch.Text = "IT is selected now";
                }
            }
        }

【问题讨论】:

    标签: c# .net asp.net checkbox repeater


    【解决方案1】:

    我认为您缺少的是,当您的页面不是回发时,您应该绑定或设置数据源

    if (!Page.IsPostBack)
        {
            rpt.DataSourceID = "";
            rpt.DataBind();
        }
    

    我认为你的情况是,在回发时你的转发器被重新绑定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-22
      • 1970-01-01
      相关资源
      最近更新 更多