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

C#-WEB: textbox or label control?

daJunkCollector
I am trying to display a column from a database table in the column of a datagrid. I am using a template column to display it.

There are two things that are important to me:
1. If DataItem.TtlInfo is too many characters to be completely seen I want "..." to be added as the last three visible characters in the control. Then, the user can view the entire varchar by mousing over (hence the tooltip).

2. I would prefer to use a label because the TextBox display looks ugly. Unfortunately, I use a TextBox now because the label won't allow me to limit the characters displayed.

So, does anyone know of a nice way to display a limited amount of character in a label control? And if the 'text' property is larger than the set amount of characters, then "..." will be concatenated at the end of the visible area (for display purposes only). Then the tooltip could be used to view the entire string.

Expand|Select|Wrap|Line Numbers
  1. <asp:TemplateColumn ItemStyle-Width="250px">
  2.    <ItemTemplate>                
  3.       <asp:TextBox ID="txtTtlInfo" runat="server" CssClass="contentblack" ToolTip='<%# DataBinder.Eval(Container,"DataItem.TtlInfo") %>' Text='<%# DataBinder.Eval(Container,"DataItem.TtlInfo") %>' TextMode="SingleLine" ReadOnly="True" width="225px" Height="20px"></asp:TextBox>
  4.    </ItemTemplate>
  5. <asp:TemplateColumn>
Dec 13 '07 #1
2 2207
Frinavale
9,735 Expert Mod 8TB
I am trying to display a column from a database table in the column of a datagrid. I am using a template column to display it.

There are two things that are important to me:
1. If DataItem.TtlInfo is too many characters to be completely seen I want "..." to be added as the last three visible characters in the control. Then, the user can view the entire varchar by mousing over (hence the tooltip).

2. I would prefer to use a label because the TextBox display looks ugly. Unfortunately, I use a TextBox now because the label won't allow me to limit the characters displayed.

So, does anyone know of a nice way to display a limited amount of character in a label control? And if the 'text' property is larger than the set amount of characters, then "..." will be concatenated at the end of the visible area (for display purposes only). Then the tooltip could be used to view the entire string.

Expand|Select|Wrap|Line Numbers
  1. <asp:TemplateColumn ItemStyle-Width="250px">
  2.    <ItemTemplate>                
  3.       <asp:TextBox ID="txtTtlInfo" runat="server" CssClass="contentblack" ToolTip='<%# DataBinder.Eval(Container,"DataItem.TtlInfo") %>' Text='<%# DataBinder.Eval(Container,"DataItem.TtlInfo") %>' TextMode="SingleLine" ReadOnly="True" width="225px" Height="20px"></asp:TextBox>
  4.    </ItemTemplate>
  5. <asp:TemplateColumn>


In the method that handles your Gridview's RowDataBound event, check the the length of the string in the cells that you want to truncate...if they're longer than the length, truncate them and add "..." instead.

I'm not sure how you would go about adding the value to the tool tip though...
Unless you set the tool tip when you are creating the datasource for the GridView...

-Frinny
Dec 13 '07 #2
In the method that handles your Gridview's RowDataBound event, check the the length of the string in the cells that you want to truncate...if they're longer than the length, truncate them and add "..." instead.

I'm not sure how you would go about adding the value to the tool tip though...
Unless you set the tool tip when you are creating the datasource for the GridView...

-Frinny
Frinny, I got it. Thanks a lot for the help.

Expand|Select|Wrap|Line Numbers
  1. <asp:Label ID="lblTtlInfo" runat="server" CssClass="contentblack" Text='<%# (DataBinder.Eval(Container,"DataItem.TtlInfo").ToString().Length > 40) ? String.Concat(DataBinder.Eval(Container,"DataItem.TtlInfo").ToString().Substring(0,40), "...") : DataBinder.Eval(Container,"DataItem.TtlInfo") %>' Tooltip='<%# DataBinder.Eval(Container,"DataItem.TtlInfo") %>' >
Dec 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bernard | last post by:
I can set the opacity of a form control Is there any way of doing this for the panel control (or textbox or label
1
by: aaa | last post by:
Hi I am trying to bind Text property of label control to datetime object (attribute from typed dataset). The problem is that I want only to show date part. Currently I use following code: ...
7
by: Grigs | last post by:
I was able to do this in .asp but not asp.net, can someone please help. I have a multi-line textbox control on a webform. Next to it is a label control. Basically I want the label control to...
6
by: hecsan07 | last post by:
I need to use a label control that depending on the page where the control is use sets the control into a sort of edit mode. That is, I need to use a label that sometimes I can type text to. Can...
6
by: jcrouse | last post by:
I am rotating some text is some label controls. In the one place I use it it works fine. In the other place I use it I can't figure out the syntax. I don't really understand the event. Where it...
8
by: Arpan | last post by:
Consider the following code snippet (my main intention is to display the current time in a Label control as & when this ASPX page is accessed/refreshed): <script runat="server"> Class Clock...
1
by: Sue | last post by:
Hello Is there an equivalent of a OnTextChangedEvent for a asp: label control in asp.Net 2.0. Every time the text of a label changes, I want the items in a listbox control cleared. Tried...
5
by: BobLaughland | last post by:
Hi There, I am trying to get some fields to align on a web page, like this, To: From: Subject: Each of the fields above have a corresponding asp:Textbox control next to it that I cannot...
3
by: Rahul Chatterjee | last post by:
I have a stored procedure which does a simple select * from MemberTable. This returns first name and last name. I want to assign this value to a label control in asp.net and display on screen. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.