databinding asp label

  • Thread starter Jeronimo Bertran
  • Start date
J

Jeronimo Bertran

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
 
G

Guest

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
 
S

Sylvain Lafontaine

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.
 
E

Eliyahu Goldin

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
 
S

Steven Cheng[MSFT]

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.)
 
Joined
Feb 10, 2008
Messages
2
Reaction score
0
I am trying to do teh same thing with lbltext=...

Can someone break down the databind.eval parameters for me?
 
Joined
Oct 1, 2010
Messages
15
Reaction score
0
Resale Rights

Get the low cost great value Private Label Rights (PLR) ebooks, articles, content, videos, plr sources, suppliers. You Can Easily Skip The Product Creation Process With A Collection Of Private Label Rights Ebooks so you Can feel Proud.:D

Resale Rights
 
Joined
Oct 1, 2010
Messages
15
Reaction score
0
o A very smart and diplomatic answer. It’s really appreciable and general.
o The society is facing problems with such laws. This has to go legal and it’s needed to be sorted at the earlier.
 
Joined
Oct 1, 2010
Messages
15
Reaction score
0
o Every dark night is followed by a bright sunny day. So, patience and attention is required and things will be fruitful in near future
 
Joined
Oct 1, 2010
Messages
15
Reaction score
0
o Well, it’s amazing. The miracle has been done. Well done.
Hat’s off. Well done, as we know that “hard work always pays off”, after a long struggle with sincere effort it’s done.
 
Joined
Oct 1, 2010
Messages
15
Reaction score
0
o The above statement is seen to be contradictory. The situation is very critical and need an experience complainer to resolve it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top