|
| |
|
|
knuttlehead
Posts: 4 Joined: 3/28/2008 Status: offline
|
Conditional HTML in formview results needed... - 3/28/2008 17:50:39
Hi, as a newbie to EW I'm getting the hang of it okay but have a delimma: I'm successfully using a formview to show my database results including a picture. Now I want to NOT show the picture if the database field 'PhotoFile' is null or empty. This field holds the url of the picture file if it exists on the server. In the past I just used asp and an If..then statement to compare the ...fp_rs.. to the value somewhere within the data connection. If the condition was met I showed the line of HTML that allowed the image to show. If not, I just skipped that line of HTML. I've tried things like the following inside the form view where the PhotFile content was fetched: <% If Eval("PhotoFile") <> "" Then %> 'HTML code to show photo <% Else 'do nothing End If %> Didn't work....please share wisdom if you can. I think my real problem is not knowing how to use and/or get hold of the data I've retrieved and use it in VB. I'm sure I'm just going about this all wrong but I just haven't had time to do in-depth study in to the .net coding yet. Thanks in advance, Knuttlehead
< Message edited by knuttlehead -- 3/29/2008 22:05:55 >
|
|
|
|
rdouglass
Posts: 9167 From: Biddeford, ME USA Status: offline
|
RE: Conditional HTML in formview results needed... - 3/30/2008 15:00:37
quote:
If Eval("PhotoFile") <> "" Then How about this way: If trim(Eval("PhotoFile")&"") > "" Then That any better?
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
knuttlehead
Posts: 4 Joined: 3/28/2008 Status: offline
|
RE: Conditional HTML in formview results needed... - 3/30/2008 18:13:06
Thanks rdouglas for your reply. Not sure how this fits my asp.net delimma: My Delimma is Not knowing the syntax required to use the <%# Eval("photofile") %> data returning method with Visual Basic to Conditionally omit a line of code in formview I tried your suggestion but got this error: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control Here's my code with your suggestion implimented: <ItemTemplate> <% If trim(Eval("PhotoFile")&"") > "" Then %><asp:Image ImageUrl='<%# Bind("PhotoFile") %>' runat="server" id="PhotoFileLabel" ImageAlign="Right" /><% Else 'Do Nothing End If %> <asp:Label Text='<%# Bind("SubPageName") %>' runat="server" id="SubPageNameLabel" /><br /> etc..... Further help appreciated... Knuttlehead
|
|
|
|
rdouglass
Posts: 9167 From: Biddeford, ME USA Status: offline
|
RE: Conditional HTML in formview results needed... - 3/30/2008 18:17:48
Can you post a little bigger chunk of code that doesn't error? That might give me a better idea as to what you're doing. Unfortunately one of my issues is that I don't use EW and use VS instead so I am not at all sure what interface you're seeing.
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
knuttlehead
Posts: 4 Joined: 3/28/2008 Status: offline
|
RE: Conditional HTML in formview results needed... - 3/30/2008 18:32:02
Surely I can... All I want to do is conditionlally show the picture only if the value of 'PhotoFile' retreived from the database is null or equals "". I believe this is the 3rd line of code here? Here is the whole section for the ItemTemplate: </InsertItemTemplate> <ItemTemplate> <asp:Image ImageUrl='<%# Bind("PhotoFile") %>' runat="server" id="PhotoFileLabel" ImageAlign="Right" /> <asp:Label Text='<%# Bind("SubPageName") %>' runat="server" id="SubPageNameLabel" /><br /> <br /> <asp:Label Text='<%# Replace(Eval("PageText"),chr(13)& chr(10),"<br>") %>' runat="server" id="PageTextLabel" /> <br /> <br /> <br /> <asp:LinkButton runat="server" Text="Edit" CommandName="Edit" id="EditButton" CausesValidation="False" /> <asp:LinkButton runat="server" Text="Delete This Page" CommandName="Delete" id="DeleteButton" CausesValidation="False" /> <asp:LinkButton runat="server" Text="Create A New Page" CommandName="New" id="NewButton" CausesValidation="False" /> </ItemTemplate> Is that enough code? Thanks a ton...Knuttlehead
|
|
|
|
rdouglass
Posts: 9167 From: Biddeford, ME USA Status: offline
|
RE: Conditional HTML in formview results needed... - 3/31/2008 12:12:16
quote:
Is that enough code? Almost. Can you just tell em is it a Repeater, a GridView, or what have you and if you're using a code-behind page. See, typically I'd build a function but I'm not at all sure if you're comfortable with functions. Are you? For instance, a function I use on a code-behind page looks like this: Public Function FixTheMoney(ByVal Numbvalue As String) As String If Trim(Numbvalue & "") = "" Then Return ("$0.00") Else Return FormatCurrency(Trim(Numbvalue), 2) End If End Function and I access it like this in a GridView template field like this: <asp:TemplateField HeaderText="Fees" SortExpression="CampaignFees"> <ItemTemplate> <asp:Label ID="Label4" runat="server" Text='<%# FixTheMoney(Eval("CampaignFees")) %>'></asp:Label> </ItemTemplate> <ItemStyle HorizontalAlign="Right" /> <FooterStyle HorizontalAlign="Right" /> </asp:TemplateField> What that does is remove all the IF..THEN stuff from the GridView and this particular one deals with Nulls as well as numerical data. If it's Null or empty, then it returns $0.00. But I'm not sure how comfortable you are with stuff like that.
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
rdouglass
Posts: 9167 From: Biddeford, ME USA Status: offline
|
RE: Conditional HTML in formview results needed... - 3/31/2008 14:13:51
quote:
Any help with that? Links. Instructions You don't *have* to use codebehind pages but IMO that's one big advantage of .NET and that is to separate the code from the markup. If you have Visual Studio (that's what I use), it's in the doc's but again, I don't know what's available for EW. But here's a pretty good explaination about how to use codebehind pages without VS. http://www.asp101.com/articles/john/codebehindnovs/default.asp Hope it helps.
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|