Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在中继器控制中查找相应的控制_C#_.net_Asp.net_Repeater - Fatal编程技术网

C# 在中继器控制中查找相应的控制

C# 在中继器控制中查找相应的控制,c#,.net,asp.net,repeater,C#,.net,Asp.net,Repeater,我有一个中继器控件,每行包含一个复选框和一个标签控件。选中复选框时。我想为相应的复选框检索标签的文本。如何获取它?将以下内容添加到复选框中。选中事件处理程序: CheckBox checkBox = (CheckBox) sender; Label label = (Label) checkBox.Parent.FindControl("LabelName"); String labelText = label.Text; rowcommand事件或rowdatabound事件,从该事件中的行

我有一个
中继器
控件,每行包含一个
复选框
和一个标签控件。选中
复选框时。我想为相应的
复选框
检索
标签的文本。如何获取它?

将以下内容添加到
复选框中。选中事件处理程序:

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

rowcommand事件或rowdatabound事件,从该事件中的行中查找2个控件值,并获取和使用值。有关更多信息,您需要使用中继器的
ItemCommand
事件,如下所示:

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

    } 

您可以从本文中获得更好的想法:

尝试访问复选框的父项(应该是重复项),然后获取标签对应的子项。使用javascript或jquery,在checked事件上编写函数并从label获取值您有大约30个问题,但没有可接受的答案!!试着接受其中的一些:Dyou将在该事件中注册一个javascript函数来检索标签值