自定义Web服务器控件数据列表 [英] Custom Web Server Control Datalist

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

问题描述

我在我的解决方案中添加了一个Web服务器控件,以创建自己的数据列表.但是我无法使其获取其数据.这是我在Web服务器控件中的代码.我做错了什么?请帮忙!

I have added an web server control in my solution where I am creating my own datalist. However I am unable to make it get its data. Here is my code in the web server control. What I am doing wrong? Please help!

protected override void RenderContents(HtmlTextWriter writer)
{
    // Place some text before the DataList.
    writer.Write("Here is some text from the RenderContent method.<br>");

    // Call the base RenderContents method.

    this.RepeatDirection = RepeatDirection.Horizontal;
    this.RepeatColumns = _nofcolumns;
    writer.Write("<ItemTemplate> <%# DataBinder.Eval(Container.DataItem, \"Merhaba\")%> </ItemTemplate>");

    base.RenderContents(writer);
}





Thanks in advance!

推荐答案

我不太确定您要在此处实现的目标,但是我可以指出一个严重的误解.您的函数RenderContents(HtmlTextWriter)应该以HTML形式呈现(部分)控件.这是发送给客户端的东西.
当我看一下您的writer.Write语句时,您似乎想写出类似ASPX页面上的代码:
I''m not quite sure of what you''re trying to achieve here, but I can point out a serious misconception. Your function RenderContents(HtmlTextWriter) is supposed to render (part of) your control as HTML. This is the stuff that gets sent to the client.
When I look at your writer.Write statement though it seems you want to write out code like it is found on ASPX pages:
<ItemTemplate> <%# DataBinder.Eval(Container.DataItem, \"Merhaba\")%> </ItemTemplate>"



虽然这种代码在在服务器端编译并运行的ASPX页面上很好用,但与HTML无关.

也许如果您多解释一下您正在努力实现的目标,我们可以提供更好的建议!

修改:
我认为这是您应该认真研究的链接: http://msdn.microsoft.com/en-us /library/zt27tfhy.aspx [ ^ ]
最终修改

最好的问候,
曼弗雷德(Manfred)



While this kind of code is fine on ASPX pages that are compiled and run on the server side it has nothing to do with HTML.

Maybe if you explained a little more what it is that you''re trying to achieve we could offer even better advice!

Modification:
I think this is a link you should study thouroghly: http://msdn.microsoft.com/en-us/library/zt27tfhy.aspx[^]
End Modification

Best regards,
Manfred


无论如何,您有可能向我建议一个可以找到答案的论坛吗?我已经在这个论坛上两次发布了这个问题,但找不到答案.同样,一旦回答了这个问题,就没有人再回答了.

最好的
Thanks anyway, is it possible for you to suggest me a forum where I can find the answer? I have posted this question twice on this forum and could not find the answer. Also once this question is answered, nobody again responds it.

ALl the best


这篇关于自定义Web服务器控件数据列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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