在数据列表的标题行中查找控件 [英] Find a Control in Header Row of Datalist

查看:86
本文介绍了在数据列表的标题行中查找控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好......

我在数据列表的标题中有一个标签....我想通过代码后面设置该标签的文本..但我不知道如何通过代码找到该控件..我是ASP.net的新手...



谢谢

Hi All....

I have a label in the header of a datalist....i want to set the text of that label through code-behind....but i don''t know how to find that control through code....i am new to ASP.net...



Thank You

推荐答案

使用FindControl()方法查找Label控件

Use FindControl() Method to find the Label control

protected void datalist_ItemDataBound(object sender, DataListItemEventArgs e)
{
    Label HeaderLabel=(Label) e.Item.FindControl("HeaderLabel");

        HeaderLabel.text="Your text";
}


DataList具有事件OnItemCreated,重写允许选择行类型:
DataList has event OnItemCreated, overriding allows select type of row:
Label _lblLabel1;
void Item_Created(Object sender, DataListItemEventArgs e)
{

   if (e.Item.ItemType == ListItemType.Footer)
   {

      __lblLabel1 =(Panel)e.Item.FindControl("lblLabel1");
     __lblLabel1.Text="";

    }

}


这篇关于在数据列表的标题行中查找控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆