Use data in repeater when Checkbox is check in ASP

2019-08-04 01:31发布

I have a repeater for showing my data . this repeater showing 2 field that one of feild is checkBox Control and other is a lable.

NOW , how can I understand text of lable when the checkBox is Checked?

I want to see text of lable in evry row that the CheckBoxes is checksd.

how do I do?

I use LINQtoSQL for get and set data from database

3条回答
姐就是有狂的资本
2楼-- · 2019-08-04 02:08

On postback, you need to loop through every row of your repeater, and grab out the checkbox control. Then you can access it's .Checked and .Text properties. If it's .Checked, then add it to a list or array. I can elaborate if needed..

查看更多
女痞
3楼-- · 2019-08-04 02:12
<asp:Repeater ID="rptX" runat="server">
<ItemTemplate>
    <asp:Label ID="lblX" runat="server" Visible='<%# Eval("IsChecked") %>' />
    <asp:CheckBox ID="chkX" runat="server" Checked='<%# Eval("IsChecked") %>' />
</ItemTemplate>
</asp:Repeater>

And code behind when you assign your data

   rptX.DataSource = SomeIEnumerableFromLinq; // which has a bool field called IsChecked
   rptX.DataBind();
查看更多
成全新的幸福
4楼-- · 2019-08-04 02:25

Page...

             <asp:CheckBox ID="chkBoxID" runat="server" OnCommand="doSomething_Checked" CommandArgument="<%# Some Binding Information%>"
                CommandName="NameForArgument">
             </asp:CheckBox>

Code Behind...

protected void doSomething_Checked(object sender, CommandEventArgs e) {

                CheckBox ctrl = (CheckBox)sender;
                RepeaterItem rpItem = ctrl.NamingContainer as RepeaterItem;
                if (rpItem != null) {
                    CheckBox chkBox = (LinkButton)rpItem.FindControl("chkBoxID");
                    chkBox.DoSomethingHere...
             }
        }
查看更多
登录 后发表回答