Adding path info to an GridView asp:Image bound column

Discussion in 'ASP .Net' started by musosdev, Mar 25, 2008.

  1. musosdev

    musosdev Guest

    Hi

    I need to add the path to my images directory to the DataUrlField of a bound
    ImageField in a GridView, but I can't work out how to do this.

    Is there a a Path property I'm missing? Or can I append to each column as it
    is inserted (by over-riding some sort of Populate method)?

    Thanks,


    Dan
     
    musosdev, Mar 25, 2008
    #1
    1. Advertising

  2. musosdev

    Masudur Guest

    On Mar 25, 10:38 pm, musosdev <> wrote:
    > Hi
    >
    > I need to add the path to my images directory to the DataUrlField of a bound
    > ImageField in a GridView, but I can't work out how to do this.
    >
    > Is there a a Path property I'm missing? Or can I append to each column as it
    > is inserted (by over-riding some sort of Populate method)?
    >
    > Thanks,
    >
    > Dan


    Hi,

    Take a look at this article...

    http://msdn2.microsoft.com/en-us/library/aa479350.aspx

    do check out how ResolveUrl method is used.

    Thanks
    Masudur
     
    Masudur, Mar 25, 2008
    #2
    1. Advertising

  3. musosdev

    Steven Cheng Guest

    Hi Dan,

    Your question here is to how to add some custom path into the GridView
    imagefield. Generally, you can use the "DataImageUrlField" and
    "DataImageUrlFormatString" property to provide basic url and formatting
    info. For example:

    <asp:ImageField DataImageUrlField="title"
    DataImageUrlFormatString="query.aspx?title={0}" ></asp:ImageField>

    this can help you generate composite url path from the databound field
    value. However, if you want further customization, I think you may consider
    either of the following means:

    1. You can use TemplateField and manuallyl put <asp:Image > control in it.
    Thus, you can use inline databinding expression and inject the Image path
    generation code logic into the databinding expression(you can define a
    custom function in codebehind and call it).

    =================
    ................
    <ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%#
    Bind("name") %>'></asp:Label>

    <asp:Image ID="img" runat="server" ImageUrl='<%#
    Your binding function or code logic here%>' />
    </ItemTemplate>
    </asp:TemplateField>
    =========================


    2. You can also use the RowDataBound event of Gridview. There, you can
    access the databound fields and customize existing controls in the GridView
    cell. e.g.

    ============
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs
    e)
    {
    Trace.Write("GridView1_RowDataBound");
    if (e.Row.RowType == DataControlRowType.DataRow)
    {

    DataRowView drv = (DataRowView)e.Row.DataItem;

    long id = (long)drv[0];

    Image img = e.Row.FindControl("img") as Image;
    img.ImageUrl = ......;


    }
    }

    ============

    Hope this helps.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.



    --------------------
    >From: =?Utf-8?B?bXVzb3NkZXY=?= <>
    >Subject: Adding path info to an GridView asp:Image bound column
    >Date: Tue, 25 Mar 2008 09:38:06 -0700


    >
    >Hi
    >
    >I need to add the path to my images directory to the DataUrlField of a

    bound
    >ImageField in a GridView, but I can't work out how to do this.
    >
    >Is there a a Path property I'm missing? Or can I append to each column as

    it
    >is inserted (by over-riding some sort of Populate method)?
    >
    >Thanks,
    >
    >
    >Dan
    >
     
    Steven Cheng, Mar 26, 2008
    #3
  4. musosdev

    musosdev Guest

    Thanks to both of you. I've sorted the problem with a TemplateField.

    Cheers, Dan.



    ""Steven Cheng"" wrote:

    > Hi Dan,
    >
    > Your question here is to how to add some custom path into the GridView
    > imagefield. Generally, you can use the "DataImageUrlField" and
    > "DataImageUrlFormatString" property to provide basic url and formatting
    > info. For example:
    >
    > <asp:ImageField DataImageUrlField="title"
    > DataImageUrlFormatString="query.aspx?title={0}" ></asp:ImageField>
    >
    > this can help you generate composite url path from the databound field
    > value. However, if you want further customization, I think you may consider
    > either of the following means:
    >
    > 1. You can use TemplateField and manuallyl put <asp:Image > control in it.
    > Thus, you can use inline databinding expression and inject the Image path
    > generation code logic into the databinding expression(you can define a
    > custom function in codebehind and call it).
    >
    > =================
    > ................
    > <ItemTemplate>
    > <asp:Label ID="Label1" runat="server" Text='<%#
    > Bind("name") %>'></asp:Label>
    >
    > <asp:Image ID="img" runat="server" ImageUrl='<%#
    > Your binding function or code logic here%>' />
    > </ItemTemplate>
    > </asp:TemplateField>
    > =========================
    >
    >
    > 2. You can also use the RowDataBound event of Gridview. There, you can
    > access the databound fields and customize existing controls in the GridView
    > cell. e.g.
    >
    > ============
    > protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs
    > e)
    > {
    > Trace.Write("GridView1_RowDataBound");
    > if (e.Row.RowType == DataControlRowType.DataRow)
    > {
    >
    > DataRowView drv = (DataRowView)e.Row.DataItem;
    >
    > long id = (long)drv[0];
    >
    > Image img = e.Row.FindControl("img") as Image;
    > img.ImageUrl = ......;
    >
    >
    > }
    > }
    >
    > ============
    >
    > Hope this helps.
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    > Delighting our customers is our #1 priority. We welcome your comments and
    > suggestions about how we can improve the support we provide to you. Please
    > feel free to let my manager know what you think of the level of service
    > provided. You can send feedback directly to my manager at:
    > .
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications.
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    > ==================================================
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    >
    > --------------------
    > >From: =?Utf-8?B?bXVzb3NkZXY=?= <>
    > >Subject: Adding path info to an GridView asp:Image bound column
    > >Date: Tue, 25 Mar 2008 09:38:06 -0700

    >
    > >
    > >Hi
    > >
    > >I need to add the path to my images directory to the DataUrlField of a

    > bound
    > >ImageField in a GridView, but I can't work out how to do this.
    > >
    > >Is there a a Path property I'm missing? Or can I append to each column as

    > it
    > >is inserted (by over-riding some sort of Populate method)?
    > >
    > >Thanks,
    > >
    > >
    > >Dan
    > >

    >
    >
     
    musosdev, Mar 27, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John E.
    Replies:
    3
    Views:
    4,472
    masoud bayan
    Mar 25, 2005
  2. Keith G Hicks
    Replies:
    3
    Views:
    770
    Keith G Hicks
    Feb 18, 2008
  3. Ravichandran Mahalingam

    Bound Column or Template Column (w dAdapater?) in DataGrid

    Ravichandran Mahalingam, Jan 9, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    224
    Ravichandran Mahalingam
    Jan 9, 2004
  4. John E.

    Move bound column to right of dynamic column in datagrid?

    John E., Mar 24, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    233
    Elton Wang
    Mar 28, 2005
  5. TS
    Replies:
    3
    Views:
    409
    Walter Wang [MSFT]
    Aug 16, 2007
Loading...

Share This Page