Solved

using if else with Databinder.eval( ) is not letting the code compile

Posted on 2003-12-01
6
1,476 Views
Last Modified: 2008-03-10
I have an itemTemplate in a datagrid. I want display an image button or a simple hyper link based upon some field vlaue in "MATRIX_ITEM_TYPE". I simply put the if else condition but that does not seem to work. Any ideas would be highly appreciated. thanks...

<asp:templateColumn>
<itemTemplate>
<tr>
<td colspan=3 align=middle>
<%# if (DataBinder.Eval(Container.DataItem, "MATRIX_ITEM_TYPE") == 3){ %>
<asp:ImageButton ID="itemType" Runat="server" ImageUrl="images/items/custom_configuration.gif"></asp:ImageButton>
<%}else{%>
 <a href="">more info</a>
<%}%>      
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
0
Comment
Question by:rxraza
  • 3
  • 2
6 Comments
 
LVL 29

Assisted Solution

by:David H.H.Lee
David H.H.Lee earned 50 total points
Comment Utility
rxraza,
Instead of
<%# if (DataBinder.Eval(Container.DataItem, "MATRIX_ITEM_TYPE") == 3){ %>

Change to
<% if (DataBinder.Eval(Container.DataItem, "MATRIX_ITEM_TYPE") == 3){ %>
-Eliminate "#". What you need is dynamically generate code based on selected criteria, not binding data into <ItemTemplate> in datagrid.

However, there are some others way to solve your problems as well. Please refer my post at this thread :
http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20806371.html

Regards
x_com
0
 
LVL 3

Accepted Solution

by:
vijay7248 earned 150 total points
Comment Utility
Hi,
You can use a function and return the value u want ......

Try this workaround:
1. Declare a label inside ur item template like this:
      <ItemTemplate>
       <asp:label runat=server
Text='<%#getpath(DataBinder.Eval(Container.DataItem, "MATRIX_ITEM_TYPE").ToString)%>'>
       </asp:label>
     </ItemTemplate>

2. Then in ur server side script add the function getpath:
       function getpath(ItType As Integer) as string
            dim path as string
                  if ItType=3 then
                     path="<img border=0 src='images/items/custom_configuration.gif' alt='Picture Available'/>"
                  else
                     path="<a href='ur path here'>more info</a>"
                  end if
            return path
       end function


Using a function for this kind of needs will avoid much confusions in the code..

Hope this helps...  :)

-Vijay


0
 

Author Comment

by:rxraza
Comment Utility
well guys:

Here is the situation. I have modified the code, now the code is as follows:
............
<ItemTemplate>
<%# getDetails(DataBinder.Eval(Container.DataItem, "MATRIX_ITEM_TYPE"))%>
</itemTemplate>
.......

Server Side function is as follows:

getDetails(matrixItemType){
   if (matrixItemType == 3){
      return "<asp:ImageButton ID=itemType Runat=server   ImageUrl=""images/items/custom_configuration.gif""></asp:ImageButton>"      
  }
  else{
     return "<a href="""">more details...</a>"
 }
}

The problem is it is returning the correct element based upon the value in the data grid column but on the page the <asp:ImageButton> is not being rendered.
Any idea about how to render this control on the page? thanks

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 3

Expert Comment

by:vijay7248
Comment Utility
Hi rxraza,
Happy to see u use my approach.

>>>>>>
The problem is it is returning the correct element based upon the value in the data grid column but on the page the <asp:ImageButton> is not being rendered.
Any idea about how to render this control on the page? thanks
>>>>>>

Why not try the ordinary HTML <img> tag  instead of using the <ASP:Image>
 button.Since u need the functionality of an image button u can put an <img> tag within <a href>.Something like this.......


getDetails(matrixItemType){
   if (matrixItemType == 3){
      return "<a href='currentpage.asp?gofunction=yes'><img border=0 src='images/items/custom_configuration.gif' alt='Picture Available'/></a>"
  }
  else{
     return "<a href="""">more details...</a>"
 }
}

Incase if u r accessing a function/sub (say Sub Test)   using the Image button.....
U can read the queryString in ur PageLoad function as::

           if Request.QueryString("gofunction")="yes" then
                     call Test
           end if

If u jus need to transfer to another page ...then give the filename in the a href..


Hope this works...     :)

-Vijay
0
 

Author Comment

by:rxraza
Comment Utility
Thanks Vijay for a descriptive explanation. The solution that you mentioned is a workaround, which will always work.

Actually I wanted to know is it possible to render the <asp:ImageButton> once it is dynamically generated
OR
it could only be rendered by the 'dll' responsible for handling .aspx scirpts

thanks in Advance
0
 
LVL 3

Expert Comment

by:vijay7248
Comment Utility
rxraza,
I'm sure there must be some way or the other to dynamically add a control through coding.
Since u r using Datagrid this could be slightly difficult.
(FYI: I'm new to .Net)

But the thing is, I've not tried that yet . sorry to say this :(
I dont have the time to test a code and give that to you as I've been put into a new project now.

I know you can do it..Jus try adding a control dynamically to the datagrid using some tutorials/helps from www...

or else you can do something similar using the AddColumn functionality of DAtagrids..

Hope this helps :)


-Vijay
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
trim spaces before first character 6 70
Set cursor to client side 3 48
two submit buttons one form 15 65
INNER JOIN ? 8 29
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now