簡體   English   中英

如何在ASP中繼器中動態更改圖像大小而不在數據庫中存儲圖像大小

[英]how to change the image size dynamically in asp repeater without store the image size in database

我有以下中繼器:

          <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

那我該怎么辦呢?

如何獲得中繼器中圖像的所有隨機高度?

任何想法?

在數據綁定之前,在包含高度的數據集中添加一列,在本示例中為H,其中包含高度。

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

用所需的高度為每一行填充此列。 可以是隨機的,也可以是您想要的值。

在轉發器中,將數據綁定到此新列

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

寬度相同

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM