473,394 Members | 1,828 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,394 software developers and data experts.

Conditional label within DataList?

Hi all,

I've got a DataList that's bound to a datasource with two columns (well, two
that matter). One is called GigDate, and one is called RescheduledFromDate.

GigDate doesn't allow NULLs, but the RescheduledFromDate does. In general,
only a GigDate will be supplied, but if a Gig is rescheduled, the GigDate is
copied to RescheduledFromDate, and the GigDate then becomes the "new" date.

I'm using a DataList instead of a Grid because it's slightly more flexible
for the design (I'm using several rows to display each record).

What I'd like to display is something like this

---- If a gig has NOT been rescheduled ----
Gig Date: xx/yy/zz
---- / ----

---- If a gig HAS not been rescheduled ----
Gig Date: xx/yy/zz
(rescheduled from xx/yy/zz)
---- / ----

I can see a few ways to do this, but I don't like the ones I've managed to
get working. One is to have a label bound to RescheduledFromDate, with
Visible bound to an expression checking for null. However, this means the
Text property has to be a custom expression too. To keep the label Text
property bound to the field directly, I could have another two labels for
the text, with the Visible properties set to the same as the
RescheduledFromDate field (one containing "(rescheduled from " and the other
just ")").

Neither of these are particularly great, and I can see instances when they'd
work even less well! (eg, if I needed an image to be displayed, as well)

What I'd *like* to do, is something like a PlaceHolder, with Visible bound
to an expression checking if the field is null, and then place literal text,
and a bound label inside.

I've tried using the PlaceHolder control, but I don't see to be able to put
anything inside it in the designer. A panel might work, but I believe this
renders out as a Table or something, and I don't want anything that pollutes
the markup unnecessarily.

I'm sure I'm missing something simple. Any offers?

Thanks!

Danny Tuppeny
Nov 19 '05 #1
3 1946
"Danny Tuppeny" <gr****@dannytuppeny.commmmmm> wrote in message
news:43***********************@ptn-nntp-reader03.plus.net...
I've tried using the PlaceHolder control, but I don't see to be able to
put anything inside it in the designer. A panel might work, but I believe
this renders out as a Table or something, and I don't want anything that
pollutes the markup unnecessarily.


The Panel renders as a DIV in IE (maybe it was FF that got a table?), which
isn't *too* bad, but I'd stil rather have something that doesn't render
HTML. I've been through all the controls in the WebControls namespace on
msdn2.microsoft.com, but nothing seems to fit. I can see a *lot* of cases
when I'd like to conditionally display a group of controls without rending
an extra DIV, or moving them into a user control - I've got to be missing
something?
Nov 19 '05 #2
Danny,

Not sure if this will fit your need but: In a similar problem what I do is query out
a dataset that has the two columns of information. But I only show one of those
database columns in the datalist. For the other visible column I have a third column
that I assign to the DataGrid's second column.

Then I do the query, then loop thru the dataset in code, and for each row set the
third column to an empty string (or DbNull.Value if you prefer) or to the string I
want to have displayed.

Only once I've made the pass thru the database in CodeBehind do I bind that dataset
to the DataGrid.

So basically you have to modify your dataset with a pass thru it to set an extra column.

e.g. "SELECT GigDate, RescheduledFromDate, 'HolderText' AS ToDisplayColumn FROM
YourTable";

Then loop thru and set the ToDisplayColumn to either "(rescheduled from xx/yy/zz)" or
to NULL or "".

You can also query out just the two columns and then add a column to the dataset
after the Fill call. I didn't do it that way. But it'd work just as well to get you
the third column. Then, again, you'd loop thru and set the third column in each row
with a foreach loop on the dataset.

Hope that helps...

Danny Tuppeny wrote:
Hi all,

I've got a DataList that's bound to a datasource with two columns (well, two
that matter). One is called GigDate, and one is called RescheduledFromDate.

GigDate doesn't allow NULLs, but the RescheduledFromDate does. In general,
only a GigDate will be supplied, but if a Gig is rescheduled, the GigDate is
copied to RescheduledFromDate, and the GigDate then becomes the "new" date.

I'm using a DataList instead of a Grid because it's slightly more flexible
for the design (I'm using several rows to display each record).

What I'd like to display is something like this

---- If a gig has NOT been rescheduled ----
Gig Date: xx/yy/zz
---- / ----

---- If a gig HAS not been rescheduled ----
Gig Date: xx/yy/zz
(rescheduled from xx/yy/zz)
---- / ----

Nov 19 '05 #3
Hi Randall,

That's certainly another way, but like the other methods, it doesn't really
sit right with me. Seems a like a lot of messing just to avoid using a Panel
because it outputs HTML :( It's also messy if I wanted to ouptut images
etc., since it means building the string in SQL, and throwing away all the
designer stuff (and ability to do server controls).

The designer's data support has *really* grown on me - I used to be of the
opinion "if you're not writing the code, it's bad code", but VWD has
completely changed my opinion, and since this site is a bit of a showcase,
I'm determined to write as little code as possible now (to show people why
they should be using asp.net 2.0, and not ASP :-( !!!)

I'll stick with the panel for now, and hope I don't have to do something
inline (that'd involve setting the panel to display: inline or float:
left!!). Thanks for you ideas anyhow :)

Danny
"Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit .com>
wrote in message news:Og**************@tk2msftngp13.phx.gbl...
Danny,

Not sure if this will fit your need but: In a similar problem what I do is
query out a dataset that has the two columns of information. But I only
show one of those database columns in the datalist. For the other visible
column I have a third column that I assign to the DataGrid's second
column.

Then I do the query, then loop thru the dataset in code, and for each row
set the third column to an empty string (or DbNull.Value if you prefer) or
to the string I want to have displayed.

Only once I've made the pass thru the database in CodeBehind do I bind
that dataset to the DataGrid.

So basically you have to modify your dataset with a pass thru it to set an
extra column.

e.g. "SELECT GigDate, RescheduledFromDate, 'HolderText' AS ToDisplayColumn
FROM YourTable";

Then loop thru and set the ToDisplayColumn to either "(rescheduled from
xx/yy/zz)" or to NULL or "".

You can also query out just the two columns and then add a column to the
dataset after the Fill call. I didn't do it that way. But it'd work just
as well to get you the third column. Then, again, you'd loop thru and set
the third column in each row with a foreach loop on the dataset.

Hope that helps...

Nov 19 '05 #4

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

Similar topics

3
by: Dude | last post by:
Below is the code - it is finding the control, and there is no error, just not assigning the text to the label <asp:DataList id="dlGoals" runat="server" onEditCommand="myListEditHandler"...
3
by: Harry | last post by:
Hi, Can anyone tell me why the below code does not work. I dont get any errors, but nor does the Text for the asp:label get set. Thanks in advance as always H
9
by: jjack100 | last post by:
I want to set the text value of a label that is within a datalist in the codebehind. Does this have to be done in the databound event? Simplified example: <asp:DataList id="dlItem"...
1
by: Ed Chiu | last post by:
Hi, I have the following item template in a datalist: <asp:LinkButton id="lnkAction" runat="server" CommandName="Action" cssClass="TabMenu"> <%# Container.DataItem("Title") %>...
1
by: | last post by:
I have a label control that I've embedded in a datalist template. I will be binding data to that label. I want to run a string formatting function on the database text before it is injected into...
7
by: rn5a | last post by:
How can I place a Label control in the FooterTemplate of a DataList control? I tried this <script runat="server"> Sub Page_Load(obj As Object, ea As EventArgs) Dim dblTotal As Double Dim...
2
by: rn5a | last post by:
Consider the following code: <script runat="server"> Sub ShowData(obj As Object, ea As EventArgs) lblDate.Text = DateTime.Now.ToString("d") lblDate.DataBind() End Sub </script> <form...
0
by: lamarant | last post by:
OK...I have a datalist that, in each row, has control and a label. What I want to happen is for the text in the label to update when its associated control is clicked. Here's what I have so...
1
by: Jim in Arizona | last post by:
On one page I have a datalist where a message is bound to a label. On another page I have the datalist which allows for the insert of new message as well as being able to edit those messages. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.