Use data in repeater when Checkbox is check in ASP.net

六月ゝ 毕业季﹏ 提交于 2019-12-11 10:04:12

问题


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


回答1:


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



回答2:


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:


<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();


来源:https://stackoverflow.com/questions/1585574/use-data-in-repeater-when-checkbox-is-check-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!