Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.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# asp.net repeater中的对象是';我的代码找不到吗?_C#_Asp.net_Attributes_Repeater - Fatal编程技术网

C# asp.net repeater中的对象是';我的代码找不到吗?

C# asp.net repeater中的对象是';我的代码找不到吗?,c#,asp.net,attributes,repeater,C#,Asp.net,Attributes,Repeater,因此,在我的asp.net应用程序中,我有一个转发器,但从我的代码中找不到转发器中的任何对象。下面是一个例子: 标记 <asp:Repeater ID="repeater_id" runat="server" DataSourceID="ExampleSource"> <HeaderTemplate> <table id="table_id">

因此,在我的asp.net应用程序中,我有一个转发器,但从我的代码中找不到转发器中的任何对象。下面是一个例子:

标记

  <asp:Repeater ID="repeater_id" runat="server"
            DataSourceID="ExampleSource">
            <HeaderTemplate>
                <table id="table_id">
                    <thead>
                        <tr>
                            <th>Example</th>
                        </tr>
                    </thead>
                    <tbody>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:Label runat="server" ID="MyLabel" />
                    </td>
                </tr>
            </ItemTemplate>

            <FooterTemplate>
                </tbody>
                </table>
            </FooterTemplate>
        </asp:Repeater>
但是,在我的aspx.cs页面中,“MyLabel”突出显示为生成错误,并带有“名称“MyLabel”在当前上下文中不存在”的描述。Anbody知道这可能是什么吗如果MyLabel位于中继器之前或之后,它工作正常。

有人知道我的问题是什么吗?请尽可能清楚地解释,我不熟悉编码


编辑:在问题中输入了错误的编码。现在已修复。

您需要循环查看中继器id.Items并找到如下标签

foreach (RepeaterItem ri in repeater_id.Items)
{
    Label MyLabel = (Label)ri.FindControl("MyLabel");
    MyLabel.Attributes.Add("Example","Example");
}

例如,请咨询本网站,了解如何格式化和设置ItemTemplate
foreach (RepeaterItem ri in repeater_id.Items)
{
    Label MyLabel = (Label)ri.FindControl("MyLabel");
    MyLabel.Attributes.Add("Example","Example");
}