【问题标题】:how to change the image size dynamically in asp repeater without store the image size in database如何在asp中继器中动态更改图像大小而不将图像大小存储在数据库中
【发布时间】:2014-12-14 15:13:05
【问题描述】:

我有以下中继器:

          <asp:Repeater runat="server" ID="rptnewfeeds">
                    <ItemTemplate>

                        <div id="main" role="main" style="width: 1153px; margin-top: -105px; left: 105px; position: absolute;">

                            <ul id="tiles">
                                <li>
                                    <asp:Image ID="Image4" runat="server" ImageUrl='<%#Eval("image") %>'  />
                                </li>
                            </ul>

                        </div>
                        </div>
                    </ItemTemplate>

                </asp:Repeater>

代码:-

        DataSet ds = new DataSet();
        string select = "select image from UserProfileData where date>='2013-09-01'";
        SqlDataAdapter da = new SqlDataAdapter(select, _connect());
        da.Fill(ds);
        rptnewfeeds.DataSource = ds;
        rptnewfeeds.DataBind();

现在绑定所有the images as same size,但我想将所有图像都绑定为different size

例如假设现在这 10 张图片有 width=200 and height=200

now i want like 1st image has width=200 and height=300
2nd image has width=200 and height=283
3rd image has width=200 and height=230
...
... and so on

那我该怎么做呢?

如何在中继器中获取所有随机高度的图像?

有什么想法吗?

【问题讨论】:

    标签: c# css asp.net .net


    【解决方案1】:

    在数据绑定之前,将一列(在本例中为 H 表示高度)添加到包含您需要的高度的数据集。

    ds.Tables[0].Columns.Add("H", typeof(int));
    

    用您需要的高度为每一行填写此列。可以是随机的,也可以是您想要的某个值。

    在中继器中,数据绑定到这个新列

     <asp:Image ID="Image4" runat="server" Height='<%#Eval("H") %>'
    

    宽度相同..

    【讨论】:

    • 你能举例说明一下吗??
    • 这完全取决于您的要求。你想要什么高度/宽度?​​
    • 我想要 height=200 和 width=200
    • 其他图片的高度应该改变
    • 因此,在执行 rptnewfeeds.DataBind() 之前将该部分编码到额外的列中,您会没事的
    猜你喜欢
    • 2016-06-08
    • 2019-12-23
    • 2013-05-04
    • 2016-12-18
    • 2019-12-05
    • 2021-12-19
    • 1970-01-01
    • 2021-11-26
    相关资源
    最近更新 更多