Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Multiline Label control in ASP.net

Posted on 2005-05-10
7
Medium Priority
?
4,417 Views
Last Modified: 2008-05-20
Hi,
I have a Datagrid that I use for data entry in an ASP.net application. In edit mode , the datagrid columns have textboxes that the users use to enter the data. Some of the columns might have data on multiple lines. When the user accepts (clicks on Save in the datagrid row) , the information in the datagrid is dsiplayed in the Label controls. But the data on multiple lines in the textboxes is displayed in one line in the datagrid.
How do I make it appear on multiuple lines in a label control also??

Thanks
0
Comment
Question by:TetraSA
  • 3
  • 3
7 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 13970850
myLabel.Text = sometext.Replace(vbCrLf, "<br/>")
0
 
LVL 1

Author Comment

by:TetraSA
ID: 13970997
Hi,
But how can I do this while rendering a datagrid?. Coz, the label is in a datagrid and the datagrid is connected to a dataset source.

Thanks
0
 
LVL 33

Expert Comment

by:raterus
ID: 13971028
how does your column look in the datagrid?, you will need to add this code in ItemDataBound
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:TetraSA
ID: 13971135
Hi,
It has a template colum which has a label control "lblProDesc". The field name of the dataset is "sProdDesc".
What statement will I have in the ItemDataBound event??

Thanks
0
 
LVL 33

Accepted Solution

by:
raterus earned 1000 total points
ID: 13971185
It will look something like this, in ItemDataBound

If e.Item.ItemType <> ListItemType.Header and e.item.ItemType <> ListITemType.Footer Then
  Dim lblProDesc as Label = e.Item.FindControl("lblProDesc")
  lblProDesc.Text = cstr(DataBinder.Eval(e.item.DataItem, "sProdDesc")).Replace(vbCrLf, "<br/")
End If
0
 
LVL 1

Author Comment

by:TetraSA
ID: 13975224
Thansk a lot. Worked perfectly.
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 21607232
you could also bind it directly in the datagrid :
replace '<%# Bind("sProdDesc") %>'
with
'<%# DataBinder.Eval(Container.DataItem, "sProdDesc").toString.Replace(vbCrLf, "<br/>") %>'
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month20 days, 19 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question