473,473 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

databinding asp label

I am currently using databing to show on an asp:label the result of
appending two database fields in the following way:
<asp:label id=textAcknowledgedBy runat="server" Text='<%# DataBinder.Eval
(dataSetEventResponse1, "Tables[spEventDetails].DefaultView.[0].UserName")
+ " from " + DataBinder.Eval(dataSetEventResponse1, "Tables
[spEventDetails].DefaultView.[0].ComputerName") %>'></asp:label>
This works fine, but now I need to make it a bit more complex and check if
the UserName field is null and in case it is, display the name of the
current user (which is obtained from a session variable).

How can I achieve this?

Thanks,

Jeronimo Bertran
Nov 19 '05 #1
4 1950
Hi Jeronimo,

I dont think there is any direct way to give conditions for a Label..

One workaound would be like....

Write a function which takes 2 parameters and do all your validations and
checks here for the label control.
And let this method populate the label control...

Hope this helps...

Need any help, do post a msg back..

Happy Coding

"Jeronimo Bertran" wrote:
I am currently using databing to show on an asp:label the result of
appending two database fields in the following way:
<asp:label id=textAcknowledgedBy runat="server" Text='<%# DataBinder.Eval
(dataSetEventResponse1, "Tables[spEventDetails].DefaultView.[0].UserName")
+ " from " + DataBinder.Eval(dataSetEventResponse1, "Tables
[spEventDetails].DefaultView.[0].ComputerName") %>'></asp:label>
This works fine, but now I need to make it a bit more complex and check if
the UserName field is null and in case it is, display the name of the
current user (which is obtained from a session variable).

How can I achieve this?

Thanks,

Jeronimo Bertran

Nov 19 '05 #2
You must set it in the Page_Load () event, something like:

private void Page_Load(object sender, System.EventArgs e)

if (! IsPostBack) {

textAcknowledgedBy.Text = ....

} else {

....

}

Inline databinding are only for the simple cases.

S. L.

"Jeronimo Bertran" <je**************@newsgroup.nospam> wrote in message
news:Xn********************************@207.46.248 .16...
I am currently using databing to show on an asp:label the result of
appending two database fields in the following way:
<asp:label id=textAcknowledgedBy runat="server" Text='<%# DataBinder.Eval
(dataSetEventResponse1, "Tables[spEventDetails].DefaultView.[0].UserName")
+ " from " + DataBinder.Eval(dataSetEventResponse1, "Tables
[spEventDetails].DefaultView.[0].ComputerName") %>'></asp:label>
This works fine, but now I need to make it a bit more complex and check if
the UserName field is null and in case it is, display the name of the
current user (which is obtained from a session variable).

How can I achieve this?

Thanks,

Jeronimo Bertran

Nov 19 '05 #3
Jeronimo,

Instead of putting databind expression in the <asp:label...>, handle
ItemDataBound event. In the event handler you can implement any logic you
wish by using normal programming in C# or VB.

Eliyahu

"Jeronimo Bertran" <je**************@newsgroup.nospam> wrote in message
news:Xn********************************@207.46.248 .16...
I am currently using databing to show on an asp:label the result of
appending two database fields in the following way:
<asp:label id=textAcknowledgedBy runat="server" Text='<%# DataBinder.Eval
(dataSetEventResponse1, "Tables[spEventDetails].DefaultView.[0].UserName")
+ " from " + DataBinder.Eval(dataSetEventResponse1, "Tables
[spEventDetails].DefaultView.[0].ComputerName") %>'></asp:label>
This works fine, but now I need to make it a bit more complex and check if
the UserName field is null and in case it is, display the name of the
current user (which is obtained from a session variable).

How can I achieve this?

Thanks,

Jeronimo Bertran

Nov 19 '05 #4
Thanks for all your suggestions,

Hi Jeronimo,

I think the two suggestions
1. Using a helper funtion (defined in page class) in your <%# %>
databinding template

2. Programly set the lable's Text in codebehind such as
lblName.Text = .....

are both ok. How do you think of them? If you have any further concerns or
questions on this, please feel free to post here. Thanks,

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 19 '05 #5

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

Similar topics

3
by: GM | last post by:
I am building the text for a resume section label in databinding with 20 or so data columns using a series of 20 or so code snippits like the following: If e.Item.DataItem("EmployerDisplay") And...
3
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method,...
4
by: Nathan Sokalski | last post by:
I have two databinding expressions (the first & last names from a DB) that I want to assign to the text property of a Label so that the result is LASTNAME,FIRSTNAME. At the moment, I have the...
6
by: Nathan Sokalski | last post by:
I am using a DataSet as the DataSource of a DataList in my code. The SQL used to get the data from the database begins with: SELECT...
1
by: dieter | last post by:
Two-way databinding (as described in http://dotnetjunkies.com/QuickStartv20/aspnet/doc/data/templates.aspx) works fine for me if I use it within aspx-files. However, I would like to use it my...
5
by: Mark R. Dawson | last post by:
Hi all, I may be missing something with how databinding works but I have bound a datasource to a control and everything is great, the control updates to reflect the state of my datasource when I...
9
by: Nathan Sokalski | last post by:
I have a very simple UserControl which contains an Image and a Label, which I use to display an image with a caption. I am using this control inside a DataList, setting the two Public variables...
11
by: =?Utf-8?B?R29rdWw=?= | last post by:
I am struck up with a problem and want anyone here to help me out. I am a beginner in .NET trying to learng DataBinding concepts. I have binded 4 text boxes with a dataset but when I say...
0
by: opedog | last post by:
I'm monkeying around with databinding, trying to learn all the ins and outs. I'm populating a label from one of my business objects properties which is a string, however, I want some formatting done...
0
by: Czechtim | last post by:
Hello, I have problem with databinding. I created small application using structure that I need to demonstrate problem. I need to change content of label when changing content of property...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.