我有以下转发器:
<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/