473,837 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
+ 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=textAcknowle dgedBy runat="server" Text='<%# DataBinder.Eval
(dataSetEventRe sponse1, "Tables[spEventDetails].DefaultView.[0].UserName")
+ " from " + DataBinder.Eval (dataSetEventRe sponse1, "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 1971
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=textAcknowle dgedBy runat="server" Text='<%# DataBinder.Eval
(dataSetEventRe sponse1, "Tables[spEventDetails].DefaultView.[0].UserName")
+ " from " + DataBinder.Eval (dataSetEventRe sponse1, "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(objec t sender, System.EventArg s e)

if (! IsPostBack) {

textAcknowledge dBy.Text = ....

} else {

....

}

Inline databinding are only for the simple cases.

S. L.

"Jeronimo Bertran" <je************ **@newsgroup.no spam> wrote in message
news:Xn******** *************** *********@207.4 6.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=textAcknowle dgedBy runat="server" Text='<%# DataBinder.Eval
(dataSetEventRe sponse1, "Tables[spEventDetails].DefaultView.[0].UserName")
+ " from " + DataBinder.Eval (dataSetEventRe sponse1, "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.no spam> wrote in message
news:Xn******** *************** *********@207.4 6.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=textAcknowle dgedBy runat="server" Text='<%# DataBinder.Eval
(dataSetEventRe sponse1, "Tables[spEventDetails].DefaultView.[0].UserName")
+ " from " + DataBinder.Eval (dataSetEventRe sponse1, "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
3769
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 e.Item.DataItem("Employer") <> "" Then Sections.Text += "<BR><B>Employer</B>: " & e.Item.DataItem("Employer") End If Is this an efficient way to build the section label's text property? Any suggestions?
3
3168
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, depending on which menu item a user selects. Each of these controls follows the same basic pattern: Get a dataset from the database and then display the results using basic databinding. Everything works fine except that I'll occaisionally get an...
4
1662
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 following which I know works when I use it by itself: text='<%# DataBinder.Eval(Container,"DataItem.membernames.lname") %>' What I need to do is somehow concatenate this databinding expression, a comma, and another databinding expression for the...
6
2317
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 members.organization,artists.artist,artists.email,artists.website,members.email FROM members INNER JOIN artists ON members.memberid=artists.memberid WHERE Notice that both tables involved in the SELECT statement have a field named
1
2823
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 codehind file and I don't know how to get it work since I did not find any equivalent for "Bind" to use in my ITemplate derived class. For my ItemTemplate, I use (int)((DataRowView)container.DataItem) as equivalent to <%# Eval ...%>
5
12535
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 update the datasource - awesome, but I have an issue with updating from a different thread. Here is my datasource, a person class that raises the PropertyChanged event: class Person : INotifyPropertyChanged {
9
2324
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 using attributes in the *.aspx page. Everything displays great for the initial load, but whenever I try to add or delete an item (I have controls to do this on the page), it does not seem to be recieving any values for the public variables. Here is...
11
1824
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 adapter.update it gives me 0 records updated! I am not getting any exceptions. Below is the complete code. Someone please help me out. using System; using System.Drawing; using System.Collections; using System.ComponentModel;
0
1137
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 on the string first. I got this working using the binding's Format event. But, I want to go one step further. Instead of using the Format event, I'm trying to set the FormatString and FormatInfo properties to make the databinding go through the...
0
4359
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 "Promena". I change content of property "Promena" from "Origin text" to "Changed text" using thread but content of label is still the same - databinding isn´t working according to my vision. Does somebody know, please, why content of label doesn´t change...
0
9843
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, 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...
0
9683
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,...
0
10882
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, 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...
0
10577
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10630
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7811
isladogs
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...
0
7005
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();...
0
5851
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4476
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 we have to send another system

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.