Solved

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

Posted on 2003-12-01
6
1,490 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 29

Assisted Solution

by:David H.H.Lee
David H.H.Lee earned 50 total points
ID: 9855422
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
ID: 9856272
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
ID: 9860475
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 3

Expert Comment

by:vijay7248
ID: 9864413
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
ID: 9868700
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
ID: 9874109
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

631 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