views:

382

answers:

1

This is my 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.

Any help will be great!

Etienne

+1  A: 
<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).

Cerebrus
Thanks, the {0} holds a paramator i know that, but how is this done in my Code?
Etienne
I don't understand. You should try the code exactly as I have suggested above.
Cerebrus
It does not work....but when i place the MyImage.jpg inside ~/pics/MyImage.jpg and i alter the DataImageUrlFormatString="~/pics/MyImage.jpg" then it does work...for some reason something is not lekker with the {0}
Etienne
Please see the sample at http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.imagefield.dataimageurlformatstring.aspx. I believe that the problem with your code lies elsewhere.
Cerebrus
MMMM, do you know how i could set the DataImageUrlFormatString in code? That might be better i think.
Etienne