用户控件与转发器中的复选框

时间:2022-03-27 10:28:18

I am a newb to C#/asp. I am trying to add a checkbox to a repeater control within a User Control. When a user clicks the checkbox I want to capture that event on the page that the user control is on. I have gotten as far as putting the checkbox in the repeater. Here is what I have in the User control.

我是C#/ asp的新手。我正在尝试向用户控件中的转发器控件添加一个复选框。当用户单击该复选框时,我想在用户控件所在的页面上捕获该事件。我已经把复选框放在转发器中了。这是我在User控件中的内容。

       <asp:Repeater ID="rOrderItems" runat="server" ><HeaderTemplate>
            <table class="mGrid" ><tr><td width="50%" align="left" >Item</td>
            <td width="20%" align="right">Qty</td>
            <td width="20%" align="center">Remove</td></td></tr></HeaderTemplate>                

            <ItemTemplate >
                <tr>
                <td> <%# DataBinder.Eval(Container.DataItem, "item.ItemNumber")%> </td>
                <td> <%# DataBinder.Eval(Container.DataItem, "Quantity")%> </td>
                 <td> <asp:CheckBox  ID="cbxRemove" AutoPostBack="true" Checked="false" OnCheckedChanged="cbxRemove_CheckedChanged"  runat="server" /></td> 
                </tr>
            </ItemTemplate>
            <FooterTemplate><tr><td>   </td><td>  </td></tr></table>
            </FooterTemplate>
            </asp:Repeater>

I am a bit lost after this. Forgive me my ignorance but I am learning.

在此之后我有点失落。请原谅我的无知,但我正在学习。

thanks

谢谢

1 个解决方案

#1


1  

It looks like you want to loop through to remove the check items. Try this:

看起来你想循环删除检查项目。尝试这个:

for (int i = 0; i < rOrderItems.Items.Count; i++) {
  CheckBox chk = (CheckBox)rOrderItems.Items[i].FindControl("cbxRemove");
  if (chk.Checked) {
    //remove this item
  }
}

Let me know how that works.

让我知道它是如何工作的。

#1


1  

It looks like you want to loop through to remove the check items. Try this:

看起来你想循环删除检查项目。尝试这个:

for (int i = 0; i < rOrderItems.Items.Count; i++) {
  CheckBox chk = (CheckBox)rOrderItems.Items[i].FindControl("cbxRemove");
  if (chk.Checked) {
    //remove this item
  }
}

Let me know how that works.

让我知道它是如何工作的。