473,321 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

If statement in a repeater control

My problem:

I have a field in a database table that contains URL info.
The values can be:
1. A Url
2. Null

If the value is null I still need to display the record but not the url
link.

How do I accomplish this with the ASP.NET repeater control?

In regular ASP I would just do something like this:

<% IF CONDITION THEN%>
HTML HTML HMTL
<%ELSE%>
ALTERNATE HTML
<%END IF%>

Thanks,
Fernando
Nov 18 '05 #1
4 8008
Hi Fernando,

As for the problem you mentioned, it is a general databinding scenario in
asp.net. First , we should see that the asp.net has completely different
programming model with the classic asp. In asp, we render all the html code
manually via script code. In asp.net, we using Databinding mechanism when
we need to display list of datas retrieved from db and contained in a
certain recordcontainer(dataset or datareader). And there're some buildin
controls for databinding display ,(datagrid/datalist/repeater). What we
need to do is specifying the databinding expression in the control's
template and assign the datasource at runtime. The asp.net databinding
expression is something like:

<%# data binding expression %>

#Data Binding Expression Syntax
http://msdn.microsoft.com/library/de...us/cpgenref/ht
ml/cpcondatabindingexpressionsyntax.asp

and we can define our own helper functions in page class and call them in
the <%# %> binding block. So as for the problem you mentioned , we can
define a helper function in the code behind such as string
checkValue(object)
{
if(object is dbnull)

return otherthing
else
return url
}

and call it in repeater's template as below:

<ItemTemplate>
..
<%# checkValue(DataBinder.Eval(..)) %>
..

</ItemTemplate>

Hope helps. If you have anything else unclear, please feel free to post
here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #2
Hi Fernando,

Thanks for your followup. I'm glad that my suggestions are of assitance.
As for the new problem you mentioned, that is because when you call a
class(no the codebehind page class)'s method, the page can't find it by
default. We can directly use the codebehind class's methods( protected or
public ones) because the actual asp.net page's class is a derived class of
the codebehind class. We don't need to import namespace for it. If we want
to call other class's member function, we need explicitly import the
class's name space. For example:

<%@Page ....%>
<%@ Import Namespace="MyWebApp.DataBinding" %>
................
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td>
<asp:TextBox id="txtOne" runat="server" Text='<%# DataHelper.GetText()
%>'>
</asp:TextBox>
.......
The DataHelper Class is under the MyWebApp.DataBinding namespace, so I
explicity import its namespace. Using the <%@Import ..%> directive

http://msdn.microsoft.com/library/en...ort.asp?frame=
true

Also, we can call the class with its full namespace so that we don't need
to import it , such as
<asp:TextBox id="txtOne" runat="server"
Text='<%# MyWebApp.databinding.DataHelper.GetText() %>'>

</asp:TextBox>

If you have anything else unclear, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 18 '05 #3
Once again, thank you!!!

And of course, I have another one for you. (and I promise as soon as I'm
proficient enough in .NET I'll help others too.)

This one is regarding name spaces.

On my development machine, I created my ASP.NET project under the "AAANEW"
directory.

Every file created inside the project uses the "AAANEW" namespace.

My production server directory is "AAA" (without the new) and I want the
namespace references everywhere in my project to be only "AAA".

How do I accomplish this? Is there any tool in VS that does that? Can I just
do a global search and replace?

Thanks,
Fernando

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:Aw**************@cpmsftngxa06.phx.gbl...
Hi Fernando,

Thanks for your followup. I'm glad that my suggestions are of assitance.
As for the new problem you mentioned, that is because when you call a
class(no the codebehind page class)'s method, the page can't find it by
default. We can directly use the codebehind class's methods( protected or
public ones) because the actual asp.net page's class is a derived class of
the codebehind class. We don't need to import namespace for it. If we want
to call other class's member function, we need explicitly import the
class's name space. For example:

<%@Page ....%>
<%@ Import Namespace="MyWebApp.DataBinding" %>
...............
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td>
<asp:TextBox id="txtOne" runat="server" Text='<%# DataHelper.GetText()
%>'>
</asp:TextBox>
......
The DataHelper Class is under the MyWebApp.DataBinding namespace, so I
explicity import its namespace. Using the <%@Import ..%> directive

http://msdn.microsoft.com/library/en...ort.asp?frame=
true

Also, we can call the class with its full namespace so that we don't need
to import it , such as
<asp:TextBox id="txtOne" runat="server"
Text='<%# MyWebApp.databinding.DataHelper.GetText() %>'>

</asp:TextBox>

If you have anything else unclear, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 18 '05 #4
Hi Fernando,

Thanks for your followup. As for the changing namespace question you
mentioned, it's different depending on the project's type you use. C# or
VB.NET:

1.For C# project, vs.net specify the namespace in each .cs file , you can
find
namespace XXXX
{
}

arround the classes in each cs file. Thus, if we want to change the
namespace for a whole project, we need to do manual replace in all the cs
files

2. In VS.NET projects, all the namespace are centrally set in the project
setting(rather than explicitly in each .vb source file). You can open the
project's properties window and find the "Root namespace" setting, we can
change this and rebuild the whole project.

Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
3
by: sck10 | last post by:
Hello, I am trying to use an If Then statement inside of a repeater control. However, I am getting the following error: Expression expected. Any help would be appreciated. Thanks in...
4
by: nicholas | last post by:
Got an asp.net data-repeater on my page. I can view the texts from the database (ex.: <%# Databinder.Eval(Container.DataItem, "contentEN") %> ), but I also would like to see the image, but only if...
1
by: olduncleamos | last post by:
Hello all, I am experimenting with the repeater control and ran into something that I wasn't expecting. I would appreciate if the experts can confirm or correct my understanding. Here is a...
7
by: charliewest | last post by:
Hello - I'm using a Repeater control to render information in a very customized grid-like table. The Repeater control is binded to a DataSet with several records of information. Within the...
8
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the...
4
by: Brad Baker | last post by:
I'm going a little crazy :) I'm trying to bind a repeater control to a dataset on page load using the following code: if (Request.QueryString != null) { string customerid = Request.QueryString;...
7
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically placing user controls that use those values. I'm...
5
by: Brad Baker | last post by:
I am trying to make a "tabbed" interface by iterating through a dataset with a conditional statement. For example: ...
12
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I'm doing a web app in VB/Dot Net 2.0. I'm probably a bit rusty and I have no experience using the repeater control. I have a user control I've created with multiple properties. I've created a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.