Results 1 to 20 of 20

Thread: [RESOLVED] [2005] Eval with database field

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Resolved [RESOLVED] [2005] Eval with database field

    Ok,
    I have a web form that contains and datasource and a datalist. The datalist uses the datasource as it's datasource. The datasource pulls all records from a table within an access database. One of the field in the access database is "image1" which contains the name of the .jpg associated with it. Now, my datalist contains an image that has a binding of

    VB Code:
    1. Eval("Image1", "~/DCRPics/1/thmb_{0}")

    Now this causes the image placeholder to look in the DCRPics/1/ folder and find a file named thmb_(name contained in the image1 field)... now this works fine.. What I am trying to do is replace the "1" in the /DCRPics/1/ path to look at the "AutoNumber" field of the record of the database that it is currently looking at.... anyone know how I can do this?
    Thanks!

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Re: [2005] Eval with database field

    Bump

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Re: [2005] Eval with database field

    bump bump

  4. #4
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: [2005] Eval with database field

    I just wanted to put in my two bits and let you know that I have no idea.

    I don't usually do databinding in this fashion. I do it in trapped events on the codebehind (which is probably the harder way to go, honestly)
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Re: [2005] Eval with database field

    Thanks for the input... I don't believe anyone else is going to reply
    Quote Originally Posted by Lord_Rat
    I just wanted to put in my two bits and let you know that I have no idea.

    I don't usually do databinding in this fashion. I do it in trapped events on the codebehind (which is probably the harder way to go, honestly)

  6. #6
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: [2005] Eval with database field

    According to:

    http://weblogs.asp.net/rajbk/archive...20/188868.aspx

    You can't.

    "...handles {0} only..."

    Thusly, you might have to resort to code behind as well.

    Another option that strikes me is to add a column to your SELECT (that gets your data) that has the entire URL:

    SELECT '~/DCRPics/' + AutoNumber + '/thmb_' + Image1
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Re: [2005] Eval with database field

    That may work.. I will play around with it... Another question for ya - Do you know how to access an imagebutton that is in a datalist from your codebehind file? Like say I wanted to do an "If" statement on my imagebutton but my imagebutton is in a data list. How can I access it?

    Quote Originally Posted by Lord_Rat
    According to:

    http://weblogs.asp.net/rajbk/archive...20/188868.aspx

    You can't.

    "...handles {0} only..."

    Thusly, you might have to resort to code behind as well.

    Another option that strikes me is to add a column to your SELECT (that gets your data) that has the entire URL:

    SELECT '~/DCRPics/' + AutoNumber + '/thmb_' + Image1

  8. #8
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: [2005] Eval with database field

    Trap the OnItemDataBound.

    Then, the row is the EventArgs variable (usually 'e') and each cell is in the cells collection:

    e.Item.Cells[iIndex]

    and then controls are children of that.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Re: [2005] Eval with database field

    Thanks bud

    Quote Originally Posted by Lord_Rat
    Trap the OnItemDataBound.

    Then, the row is the EventArgs variable (usually 'e') and each cell is in the cells collection:

    e.Item.Cells[iIndex]

    and then controls are children of that.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Re: [2005] Eval with database field

    Can you give me an example of this? I've never had to trap an event..

    Thanks

    Quote Originally Posted by Lord_Rat
    Trap the OnItemDataBound.

    Then, the row is the EventArgs variable (usually 'e') and each cell is in the cells collection:

    e.Item.Cells[iIndex]

    and then controls are children of that.

  11. #11
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: [2005] Eval with database field

    Click the datagrid, go to the properties pane and then the actions subsection. There is an action for OnItemDatabound.

    Double click in the blank field at that action and it will set up the appropriate event handler. Once you have the event handler in place, that is where you use the 'e' item from above. I can dig up code if it is needed, but it has been a while since I have had a project that required that level of love. If you do need it, let me know.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Re: [2005] Eval with database field

    Ok, I will try this when I get back to work tomorrow. Thanks alot for your time, I appreciate it. I will let you know how it goes..
    Quote Originally Posted by Lord_Rat
    Click the datagrid, go to the properties pane and then the actions subsection. There is an action for OnItemDatabound.

    Double click in the blank field at that action and it will set up the appropriate event handler. Once you have the event handler in place, that is where you use the 'e' item from above. I can dig up code if it is needed, but it has been a while since I have had a project that required that level of love. If you do need it, let me know.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Re: [2005] Eval with database field

    Rat,
    I have this event handler

    Code:
    Protected Sub DataList2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList2.ItemDataBound
        End Sub
    If I type e.Items. there is not a .cells.... ?? Also, this is on a datalist, not a datagrid.

    Quote Originally Posted by Lord_Rat
    Click the datagrid, go to the properties pane and then the actions subsection. There is an action for OnItemDatabound.

    Double click in the blank field at that action and it will set up the appropriate event handler. Once you have the event handler in place, that is where you use the 'e' item from above. I can dig up code if it is needed, but it has been a while since I have had a project that required that level of love. If you do need it, let me know.

  14. #14
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: [2005] Eval with database field

    OK, then the cells part is just not needed.

    There should be a controls property. I beleive you can index the controls by name. See also if the e or e.Item has a FindControl if not.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Re: [2005] Eval with database field

    Rat,
    This is what I have as an event:
    Code:
    Protected Sub DataList2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList2.ItemDataBound
    
            If e.Item.FindControl("ImageButton2").Visible = True Then
                e.Item.FindControl("ImageButton2").Visible = False
            End If
        End Sub
    So shouldn't this change my ImageButton2 that is in my DataList2 to not be visible? Because it runs through this code but the ImageButton is still visible...
    THanks

    Quote Originally Posted by Lord_Rat
    OK, then the cells part is just not needed.

    There should be a controls property. I beleive you can index the controls by name. See also if the e or e.Item has a FindControl if not.

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Re: [2005] Eval with database field

    Nevermind... that does work.. I was looking at the wrong Image.. Is there a property to check on a image button that you can see if the image was found or not?


    Quote Originally Posted by jre1229
    Rat,
    This is what I have as an event:
    Code:
    Protected Sub DataList2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList2.ItemDataBound
    
            If e.Item.FindControl("ImageButton2").Visible = True Then
                e.Item.FindControl("ImageButton2").Visible = False
            End If
        End Sub
    So shouldn't this change my ImageButton2 that is in my DataList2 to not be visible? Because it runs through this code but the ImageButton is still visible...
    THanks

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Re: [2005] Eval with database field

    Nevermind. Got it!!!

    VB Code:
    1. Dim I As ImageButton
    2.         I = e.Item.FindControl("ImageButton2")
    3.  
    4.         If I.ImageUrl.EndsWith(".jpg") = False Then
    5.             e.Item.FindControl("ImageButton2").Visible = False
    6.         End If

    This works if you want to see if your image button in a datalist has a .jpg file type or not....

    Thanks for all your help lord rat


    Quote Originally Posted by jre1229
    Nevermind... that does work.. I was looking at the wrong Image.. Is there a property to check on a image button that you can see if the image was found or not?

  18. #18
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: [RESOLVED] [2005] Eval with database field

    Cool glad you got it. =)
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Re: [RESOLVED] [2005] Eval with database field

    Thanks!
    Could you check this post out? I can't get any replies and it's put a hamper on my progress.

    http://www.vbforums.com/showthread.php?t=404322

    Quote Originally Posted by Lord_Rat
    Cool glad you got it. =)

  20. #20
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: [RESOLVED] [2005] Eval with database field

    I saw it, I am just not sure.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width