访问控制DataList控件中从HeaderTemplate中codebehind [英] accessing controls in datalist headertemplate from codebehind

查看:117
本文介绍了访问控制DataList控件中从HeaderTemplate中codebehind的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序,其HeaderTemplate中有lable.Now我需要从$访问拉布勒C $ cbehind.How我可以做一个DataList ..

I have a datalist in my application whose headertemplate has a lable.Now i need to access the lable from codebehind.How can i do that..

code

      <asp:DataList ID="Dlitems" runat="server" RepeatDirection="Horizontal" RepeatColumns="4"
                        CellPadding="0" CellSpacing="15" OnItemCommand="Dlitems_ItemCommand">
                        <HeaderTemplate>
                              <asp:Label ID="lblcat" runat="server" Text="" />
                        </HeaderTemplate>

注意:我需要访问拉布勒 lblcat 从HeaderTemplate中..

NOTE:I need to access the lable lblcat from headertemplate..

推荐答案

附加 OnItemDataBound 事件与DataList控件类似这样

Attach OnItemDataBound event with your datalist like this

<asp:DataList ID="Dlitems" runat="server" RepeatDirection="Horizontal" RepeatColumns="4"
CellPadding="0" CellSpacing="15" OnItemCommand="Dlitems_ItemCommand" 
OnItemDataBound="Dlitems_ItemDataBound">
...

和定义它像这样

protected void Dlitems_ItemDataBound(Object sender, DataListItemEventArgs e)
{
   if (e.Item.ItemType == ListItemType.Header)
   {
       Label lblCat = (Label)e.Item.FindControl("lblcat");
       lblCat.Text = "Changed!";

    }    
}

这篇关于访问控制DataList控件中从HeaderTemplate中codebehind的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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