且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在“数据列表"视图中使用查找控件...?

更新时间:2023-02-24 19:55:16

您可能正在尝试调用FindControl在DataList本身上.
这是不可能的,因为没有具有给定ID的Label类型的项目.而是有许多模板化的DataList项,每个项包含2个标签,其ID为"Label1"和"Label2".因此,您必须在DataList的项目上调用FindControl.

You''re probably trying to call FindControl on the DataList itself.
That is not possible because there is no item of type Label with the given ID. Instead there are a lot of templated DataList items each containing 2 labels with the IDs "Label1" and "Label2". Due to that you have to call FindControl on the DataList''s items.

foreach( var item in DataList1.Items )
{
    Label label1 = (Label)item.FindControl( "Label1" );
    ...
}