Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-12-01
6
Medium Priority
?
1,498 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 200 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 600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

660 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