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

fitting label dimensions to string length

I have a method that is returning a string which can be of any length.
Once this string is returned I want to display it on screen in a label
control. How can I make the label control's height and width be
flexible so that it always fits the length of the string it contains?

<asp:Label ID="lblSQL" runat="server" Height="600" Width="600"
BackColor="blue" ForeColor="white" Font-Names="Verdana"
Font-Size="Small"></asp:Label>

protected void Page_Load(object sender, EventArgs e)
{
ViewState["CountGUID"] = Request.QueryString["GUID"];

string strCountSQL =
GetCountSql(ViewState["CountGUID"].ToString());

lblSQL.Text = strCountSQL;
}
*** Sent via Developersdex http://www.developersdex.com ***
Nov 14 '08 #1
2 2590
"Mike P" <mi*******@gmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>I have a method that is returning a string which can be of any length.
Once this string is returned I want to display it on screen in a label
control. How can I make the label control's height and width be
flexible so that it always fits the length of the string it contains?

<asp:Label ID="lblSQL" runat="server" Height="600" Width="600"
BackColor="blue" ForeColor="white" Font-Names="Verdana"
Font-Size="Small"></asp:Label>
Don't specify any Height or Width. Just assign the Text of the label. It
will merely render it as HTML into the containing page. It is up to the
browser to wrap it around as needed in a flexible way so that the whole text
will be accomodated on the label. This will happen without your needing to
do anything special, unless your HTML markup has placed the label inside an
inflexible container, in which case you will have to modify that design.
This is all done on the HTML design; there is nothing to do on the C# side,
which is what this forum is about.

Nov 14 '08 #2
On Nov 14, 10:28*am, Mike P <mike.p...@gmail.comwrote:
I have a method that is returning a string which can be of any length.
Once this string is returned I want to display it on screen in a label
control. *How can I make the label control's height and width be
flexible so that it always fits the length of the string it contains?

<asp:Label ID="lblSQL" runat="server" Height="600" Width="600"
BackColor="blue" ForeColor="white" Font-Names="Verdana"
Font-Size="Small"></asp:Label>

protected void Page_Load(object sender, EventArgs e)
* * * * {
* * * * * * ViewState["CountGUID"] = Request.QueryString["GUID"];

* * * * * * string strCountSQL =
GetCountSql(ViewState["CountGUID"].ToString());

* * * * * * lblSQL.Text = strCountSQL;
* * * * }

*** Sent via Developersdexhttp://www.developersdex.com***
If you do not specify the width it will ocupy as much as it needs or
can, If the label is inside a control (like a TD or a DIV) with an
especific width it will occupy as most as the size of the containing
tag.
Nov 14 '08 #3

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

Similar topics

2
by: Roggey | last post by:
Hello I'm using System.Windows.Forms.Label and I want to add some text, where one or more words are bold or italic. I tried it with html tags but does not work. Somewhere i did read it should...
1
by: jack-e | last post by:
Hi, An easy on I'm guessing! How do I restrict the length of a label? I have tried setting the width to say 200px but if the user inputs a continuous line of characters it's doesn't...
1
by: ngreplies | last post by:
I am using a label as a tooltip box because I need to be able to change the background of the box depending on the information it is representing. That aside, I need to be able to auto-size the...
3
by: Robert W. | last post by:
Long ago I developed a simple algorithm for calculating how much space is required to display a multi-line label in a limited width. It seemed to be working okay but then my testing revealed a...
0
by: Anish G | last post by:
Hi, I am trying to dispaly multiple label images in to a browser using response.binarywrite(). But the images are getting over written.I am attaching the code with this, Please help me out to...
2
by: Miles | last post by:
Hi all, Wondering if anyone can help me. If i have an associative array: $arr = array( "one" =array(1, 2, 3), "two" =array(5, 6), "three" =array(7,8,9,10) .... "n" =array(p,q,r....)
2
by: Adam Teale | last post by:
hey guys Is there a builtin/standard install method in python for retrieving or finding out an image's dimensions? A quick google found me this:...
11
by: Peter Larsen [] | last post by:
Hi, I have two questions related to the Label control. How do i prevent the label from expand the canvas into 2 lines (word wrap) ?? At the moment i set AutoSize to false (to prevent the word...
1
by: Mike P | last post by:
I have a method that is returning a string which can be of any length. Once this string is returned I want to display it on screen in a label control. How can I make the label control's height and...
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.