开发者

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

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


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


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜