如何访问数据列表项目 [英] how to access items from datalist

查看:84
本文介绍了如何访问数据列表项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从后面的页面文件访问Label5(default.aspx.cs)?

 <&ItemTemplate中GT;             < ASP:图片ID =Image1的=服务器/>
        < ASP:超链接ID =HyperLink1的CssClass =nav_url_odg=服务器><%#的eval(用户)%>< / ASP:超链接> &所述;跨度类=odgovorio> JE odgovorio:或其可/跨度>&所述峰; br />
       < D​​IV>
           < ASP:标签ID =Label5=服务器文本=>< / ASP:标签>< / DIV>
    < / DIV>
    < BR />< / DIV> < / DIV>
      < / ItemTemplate中>        < / ASP:DataList控件>


解决方案

这是OnItemDataBound事件处理程序添加到您的标记为DataList:

 < ASP:DataList控件=服务器OnItemDataBound =datalist_ItemDataBound>

然后在你的code的后面,你可以检查的项目类型,并找到其ID标签控件:

 无效datalist_ItemDataBound(对象发件人,DataListItemEventArgs E)
    {
        如果(e.Item.ItemType == ListItemType.Item)
        {
            标签label5 =(标签)e.Item.FindControl(label5);
            //现在你有每个绑定行存取
        }
    }

How to access to Label5 from behind page file(default.aspx.cs)?

         <ItemTemplate>

             <asp:Image ID="Image1" runat="server" />
        <asp:HyperLink ID="HyperLink1" CssClass="nav_url_odg" runat="server"><%# Eval("user") %></asp:HyperLink> <span class="odgovorio">je odgovorio:</span><br />
       <div>
           <asp:Label ID="Label5" runat="server" Text=""></asp:Label></div>
    </div>
    <br /></div> </div>
      </ItemTemplate>

        </asp:DataList>

解决方案

Add an OnItemDataBound event handler to your markup for the DataList:

<asp:DataList runat="server" OnItemDataBound="datalist_ItemDataBound">

Then in your code behind you can to check the item type, and find the label control by its id:

    void datalist_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item)
        {
            Label label5 = (Label)e.Item.FindControl("label5");
            // now you have access for each bound row
        }
    }

这篇关于如何访问数据列表项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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