karthik k
karthik k

Reputation: 3991

find the corresponding control in repeater control

I have a Repeater control which contains a CheckBox and a lable control in each row. When a CheckBox is selected. I want to retrieve the text of the Label for the corresponding CheckBox. How to get it?

Upvotes: 2

Views: 1571

Answers (3)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

You need to use the ItemCommand event of the Repeater as follows:

protected void rep1_ItemCommand(object source, RepeaterCommandEventArgs e) 
    { 
        if (e.CommandName == "Command") 
        { 
            Label lbl = e.Item.FindControl("labelID") as Label; 
            lbl.Text //
            CheckBox chk= e.Item.FindControl("chkId") as CheckBox; 
            chk.Checked //
        } 

    } 

You can get a better idea from this article: ASP.Net Repeater OnItemCommand Event using C#

Upvotes: 1

MLS
MLS

Reputation: 895

rowcommand event or rowdatabound event, find the 2 controls values from row in that event and get and use values . for more info http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx

Upvotes: 0

Akram Shahda
Akram Shahda

Reputation: 14781

Add the following to the CheckBox.Checked event handler:

CheckBox checkBox = (CheckBox) sender;
Label label = (Label) checkBox.Parent.FindControl("LabelName");
String labelText = label.Text;

Upvotes: 4

Related Questions