如何覆盖Datalist中被渲染成的div,而不是表? [英] How To Override Datalist To Be Rendered Into Divs Instead Of Table?

查看:310
本文介绍了如何覆盖Datalist中被渲染成的div,而不是表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要呈现DataList控件来的div,而不是表,重复列将固定通过DIV浮动的风格。

i want to render datalist to divs instead of table, and the repeat columns will fixed by float style on div.

因此​​,任何人知道一个一个覆盖render方法做到这一点。

so any one know a an override render method do that.

感谢

推荐答案

我找到了解决办法,但我把它发布到所有;

i found the solution but i post it to all;

有些用户建议使用中继器,这就是是正确的,
但这种情况下,更换格,而不是表中的DataList

Some users suggest to use repeater and that's is right, but for that case to replace div instead of table in datalist

RepeatLayout=RepeatLayout.Flow 

这将使其与BR跨越
但使用水平RepeatDirectionwil删除与跨度渲染BR但仍项目

this will make it span with br but using Horizontal RepeatDirectionwil remove br but still items rendered with span

RepeatDirection=RepeatDirection.Horizontal 

西港岛线删除与跨度渲染BR但仍项目

wil remove br but still items rendered with span

所以重写RenderContents创建自己的div之外跨度可能会删除BR如果你不使用水平RepeatDirection,像

so override RenderContents to create your own divs outside span and may remove br if you do not use Horizontal RepeatDirection , like

protected override void RenderContents(HtmlTextWriter w)
{
    writer.WriteBeginTag("div");
    writer.WriteAttribute("id", this.ClientID);
    writer.WriteAttribute("class", cssClass);
    writer.Write(HtmlTextWriter.TagRightChar);
    foreach (DataListItem li in this.Items)
    {
        writer.WriteBeginTag("div");
        writer.WriteAttribute("id", li.ClientID);
        writer.WriteAttribute("class", li.CssClass);
        writer.Write(HtmlTextWriter.TagRightChar);
        li.CssClass = null; // clear css not to added in span
        li.RenderControl(w);
        writer.WriteEndTag("div");
    }
    writer.WriteEndTag("div");

}

我的问候

这篇关于如何覆盖Datalist中被渲染成的div,而不是表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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