-
May 2nd, 2006, 01:58 PM
#1
Thread Starter
Fanatic Member
[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:
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!
-
May 3rd, 2006, 02:03 PM
#2
Thread Starter
Fanatic Member
Re: [2005] Eval with database field
-
May 5th, 2006, 06:32 AM
#3
Thread Starter
Fanatic Member
Re: [2005] Eval with database field
-
May 5th, 2006, 01:16 PM
#4
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)
-
May 5th, 2006, 01:32 PM
#5
Thread Starter
Fanatic Member
Re: [2005] Eval with database field
Thanks for the input... I don't believe anyone else is going to reply
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)
-
May 5th, 2006, 01:42 PM
#6
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)
-
May 5th, 2006, 01:53 PM
#7
Thread Starter
Fanatic Member
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?
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
-
May 5th, 2006, 03:08 PM
#8
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)
-
May 8th, 2006, 06:36 AM
#9
Thread Starter
Fanatic Member
Re: [2005] Eval with database field
Thanks bud
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.
-
May 8th, 2006, 07:22 AM
#10
Thread Starter
Fanatic Member
Re: [2005] Eval with database field
Can you give me an example of this? I've never had to trap an event..
Thanks
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.
-
May 8th, 2006, 03:14 PM
#11
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)
-
May 8th, 2006, 05:00 PM
#12
Thread Starter
Fanatic Member
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..
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.
-
May 9th, 2006, 11:50 AM
#13
Thread Starter
Fanatic Member
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.
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.
-
May 9th, 2006, 11:56 AM
#14
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)
-
May 9th, 2006, 12:43 PM
#15
Thread Starter
Fanatic Member
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
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.
-
May 9th, 2006, 12:45 PM
#16
Thread Starter
Fanatic Member
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?
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
-
May 9th, 2006, 12:51 PM
#17
Thread Starter
Fanatic Member
Re: [2005] Eval with database field
Nevermind. Got it!!!
VB Code:
Dim I As ImageButton
I = e.Item.FindControl("ImageButton2")
If I.ImageUrl.EndsWith(".jpg") = False Then
e.Item.FindControl("ImageButton2").Visible = False
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
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?
-
May 9th, 2006, 02:03 PM
#18
Re: [RESOLVED] [2005] Eval with database field
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)
-
May 9th, 2006, 02:06 PM
#19
Thread Starter
Fanatic Member
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
Originally Posted by Lord_Rat
Cool glad you got it. =)
-
May 9th, 2006, 02:32 PM
#20
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|