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 4 8026
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/cpcondatabindin gexpressionsynt ax.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(obje ct)
{
if(object is dbnull)
return otherthing
else
return url
}
and call it in repeater's template as below:
<ItemTemplate >
..
<%# checkValue(Data Binder.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.)
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="MyWe bApp.DataBindin g" %>
............... .
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td>
<asp:TextBox id="txtOne" runat="server" Text='<%# DataHelper.GetT ext()
%>'>
</asp:TextBox>
.......
The DataHelper Class is under the MyWebApp.DataBi nding 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.databi nding.DataHelpe r.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.)
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.m icrosoft.com> wrote in message
news:Aw******** ******@cpmsftng xa06.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="MyWe bApp.DataBindin g" %> ............... <body> <form id="Form1" method="post" runat="server"> <table width="100%" align="center"> <tr> <td> <asp:TextBox id="txtOne" runat="server" Text='<%# DataHelper.GetT ext() %>'> </asp:TextBox> ......
The DataHelper Class is under the MyWebApp.DataBi nding 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.databi nding.DataHelpe r.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.)
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.) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 which is related to the repeater. In the code shown below, if I call Repeater1.Controls.Count in the OnInit (the code fragment was highlighted in yellow) , the viewstate for the repeater will be lost during the postback. You can re-produce this...
|
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 advance,
|
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 there is one.
So in the repeater there should be someting like:
if ( the_image_field <> "" ) then
show the image with the filename from the database field
end if
|
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 fragment of a very simple page that I wrote that will drill
down into the displayed item. The result is to be display on the same
page so that the user can keep on drilling down:
|
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 Repeater control, I've placed
DropDownLists and CheckBoxes.
When the user has updated the information, he/he clicks the submit button
which is outside the scope of the Repeater control.
| |
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 way I'm going
about doing this might be a little off. I'd appreciate some help.
Below is the code I have thus far but I'm not sure how to reference the
user control within the foreach loop.
<asp:Panel ID="pnlRosterProfile" runat="Server" />
|
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;
//open connection
SqlConnection m_conn = new SqlConnection("Server=server;
Database=database; UId=username; Pwd=password");
|
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 attempting to bind a user control I've written, "ImageBox", to a
repeater.
The user control takes a custom property, "ContentID", that will execute a
database lookup and load an image.
|
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:
----------------------------------------------------------------------------------------------------------------------
| <a href="config.aspx?siteid=FIEJGIE">Site 1</a| Site 2 | <a
href="config.aspx?siteid=DFOWEMF">Site 3</a>|
In the example above site 2 is the "current" tab.
I have the following code at the top of my...
|
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
test page and I've managed to bind the usercontrol to a repeater and display
some data in the following fashion:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1">
<ItemTemplate >
<uc1:AUserControl runat="server"...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |