c# - 如何在不将图像大小存储在数据库中的情况下在asp repeater中动态更改图像大小

标签 c# css asp.net .net

我有以下转发器:

          <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();

现在它绑定(bind)所有相同大小的图像,但我想将所有图像绑定(bind)为不同大小

例如假设现在 10 张图像有 width=200 和 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

那我该怎么做呢?

我怎样才能在中继器中获得图像的所有随机高度?

有什么想法吗?

最佳答案

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

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

用您需要的高度为每一行填充此列。随机或具有您想要的某些值。

在转发器中,数据绑定(bind)到这个新列

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

宽度相同..

关于c# - 如何在不将图像大小存储在数据库中的情况下在asp repeater中动态更改图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26452074/

相关文章:

c# - 运行时程序集位置更改

c# - 如何处理Datagridview中Button Column的点击事件?

css - 如何在 css 文件中使用 bootstrap?

jquery - 添加基于值的 CSS/JQuery 条件格式 Oracle Apex 表单

c# - 缓存项永不过期

c# - 对什么是基于 REST 的 API 感到困惑

c# - 如何在Azure Function中配置OpenApiRequestBody?

css - 如何将下拉菜单放在导航栏中?

c# - 将日期插入文本框,然后在日历 asp.net c# 中选择该日期

asp.net - ASP.NET 使用函数来生成 session ID?