用户控制问题 [英] Problems with User Control

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

问题描述

我无法理解为什么这不起作用...

我有一个代表横幅的用户控件

用户控件如下所示:

相交的那条线...

Hi i can''t get my head around why this isn''t working...

I have a user control that represents a banner

The user control looks like this:

The line that is intersting...

<asp:Label ID="HeaderText" runat="server" />



和.cs文件



And the .cs file

public string BannerText { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        HeaderText.Text = BannerText;
    }



如此..当我在如下所示的内容页面中分配属性BannerText时,效果很好...



Soo.. when I assign the property BannerText in a contentpage like below it works great...

<Offer:Banner ID="B1" BannerText="foobar" runat="server" />



但是例如在ListView中,无法从下面的数据库中读取数据.没有运行时错误,那里没有文本(而且我确定sql-query会返回一个值,因为我分别对此进行了调试)



But for instance in a ListView, reading from a database like below it doesn''t work. No run time error there is just no text there (and i know for sure the sql-query returns a value as i dubugged this separatly)

<Offer:Banner ID="B1" BannerText=''<%# Eval("OfferText") %>'' runat="server" OfferImage="1234567.png" />



它必须是Eval返回的数据类型,但是这将是运行时错误...哦,我迷路了....



It has to be something with the datatype that Eval is returning but that it would be a run time error... oh, I''m lost....

推荐答案

尝试使用
DataBinder.Eval(Container.DataItem, FieldName) 





i.e

BannerText=''<%# DataBinder.Eval(Container.DataItem, "OfferText") %>''


这篇关于用户控制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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