如何从文件夹中将我的图像显示在GridView中?

时间:2020-12-15 00:34:10

This is my Gridview

这是我的Gridview

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" Height="191px"
        Width="333px">
        <Columns>
            <asp:ImageField HeaderText="Image">
            </asp:ImageField>
            <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
            <asp:BoundField DataField="Rate_Type" HeaderText="Rate_Type" SortExpression="Rate_Type" />
        </Columns>
    </asp:GridView>

This is in my Code Behind inside my Page Load.............

这是我的页面加载中的代码背后.............

        SqlConnection myConnection;
        DataSet dataSet = new DataSet();
        SqlDataAdapter adapter;

        //making my connection
        myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);

        adapter = new SqlDataAdapter("Select ID, Rate_Type from Rate_Record", myConnection);

        adapter.Fill(dataSet, "MyData");

        GridView2.DataSource = dataSet;
        GridView2.DataBind();

Now as you will see i have a ImageField inside my gridview. When the ID = 1 then i want to show the image located here ~/pics/ID1/MyImage.jpg and so on and so on. I also want to show a Thumbnail of the Image so the User dont have to download the WHOLE image.

现在您将看到我在gridview中有一个ImageField。当ID = 1然后我想显示位于这里的图像〜/ pics / ID1 / MyImage.jpg等等。我还想显示图像的缩略图,以便用户无需下载整个图像。

Any help will be great!

任何帮助都会很棒!

Etienne

艾蒂安

1 个解决方案

#1


1  

<asp:ImageField HeaderText="Image" DataImageUrlField="ID"
  DataImageUrlFormatString="~/pics/ID{0}/MyImage.jpg"
    AlternateText="Image Description" ReadOnly="true" />

Ideally you should have thumbnail images in this folder. Another way is to have thumbnail images prefixed with an identifier such as "thumb_" (thumb_MyImage.jpg).

理想情况下,您应该在此文件夹中包含缩略图。另一种方法是使缩略图图像前缀为诸如“thumb_”(thumb_MyImage.jpg)之类的标识符。

#1


1  

<asp:ImageField HeaderText="Image" DataImageUrlField="ID"
  DataImageUrlFormatString="~/pics/ID{0}/MyImage.jpg"
    AlternateText="Image Description" ReadOnly="true" />

Ideally you should have thumbnail images in this folder. Another way is to have thumbnail images prefixed with an identifier such as "thumb_" (thumb_MyImage.jpg).

理想情况下,您应该在此文件夹中包含缩略图。另一种方法是使缩略图图像前缀为诸如“thumb_”(thumb_MyImage.jpg)之类的标识符。