473,769 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#-WEB: textbox or label control?

daJunkCollector
76 New Member
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.TtlInf o 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 2247
Frinavale
9,735 Recognized Expert Moderator Expert
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.TtlInf o 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
daJunkCollector
76 New Member
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
485
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
11822
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: this.dv = new DataView(this.ds.Person); this.labelBirth.DataBindings.Add("Text", this.dv, "BirthdayDate"); When I do this, the text shown is, for example,
7
1296
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 automatically reflect the contents of the textbox control. I did this through script before. The following is the script I am using now. <script language=javascript> setInterval('UpdateMemoDisplay()', 1000);
6
1075
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 this be done? or Is there another control I can use to accomplish this (web control or HTML)? HS
6
3163
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 works fine, it seems to fire when the form changes visibility. Here is the code. Private Sub lblP1JoyUp_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles lblP1JoyUp.Paint If lblP1JoyUp.Visible = True Then Dim...
8
1931
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 Sub SetTime(ByVal intSec As Integer, ByVal intMin As Integer, ByVal intHour As Integer) Dim lblTime As New System.Web.UI.WebControls.Label lblTime.Text = "Current Time: " & intHour & ":" & intMin &
1
403
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 doing as textbox and gave the ReadOnly="True" and border=0 to mimic a label control, but since the Readonly is set to true, the "OnTextChanged" event does not get fired.
5
11804
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 get to lign up. I have this code,
3
1548
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 am a newbie to ASP.net Can anyone please explain the sql querying and assignment portion of this task Thanks
0
9420
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
10205
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
10035
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
9984
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,...
0
9851
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
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
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.