views:

459

answers:

3

hi

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

A: 
<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();
CRice
A: 

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...
             }
        }
Alexander
+1  A: 

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

Nicholas H