468,107 Members | 1,451 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

how to implement tooltip

Hello

I am using a tooltip in one of my column in datagrid.
I want to show only 1st 20 characters and rest of the text to be shown in tooltip .
for this i need to write a function.

here is my code

Expand|Select|Wrap|Line Numbers
  1. <asp:TemplateField HeaderText="CommentText">
  2.                <ItemTemplate>
  3.                 <asp:Labelid="lbl"text='<%#tooltip(System.Convert.ToString(Eval("CommentText"))) %>' runat="server" ToolTip='<%#Eval("CommentText") %>'></asp:Label>
  4.                </ItemTemplate>
  5.                  </asp:TemplateField>  
  6.  
Expand|Select|Wrap|Line Numbers
  1. public string tooltip(String input)//function is to display only 1st 20characters
  2. {      
  3.         char[] delimiterChars = { ' ' };
  4.         string[] words = input.Split(delimiterChars);
  5.  
  6.             string output = "";
  7.             //rebuilds string without new word
  8.             for (int x = 0; x != 20; x++)
  9.             {
  10.                 if (x == 0)
  11.                 {
  12.                     output = words[x].ToString();
  13.                 }
  14.                 else
  15.                 {
  16.                     output = output+" "+words[x];
  17.                 }
  18.             }
  19.  
  20.         return output;
  21.     }
I am not sure whether my function is correct or not.
I am getting error
Index was outside the bounds of the array.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Expand|Select|Wrap|Line Numbers
  1. Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.
  2.  
  3. Source Error:
  4.  
  5. Line 31:                 else
  6. Line 32:                 {
  7. Line 33:                     output = output+" "+words[x];
  8. Line 34:                 }
  9. Line 35:             }
please help

Thank You
Oct 10 '08 #1
2 1197
Curtis Rutland
3,256 Expert 2GB
Please use [code] tags when posting code.

Mod.
Oct 10 '08 #2
tlhintoq
3,525 Expert 2GB
There is no real reason to do the elaborate if...else of lines 6-17.
If the string 'output' is initialized to "" or string output = string.empty; either one it is still perfectly acceptable to += your next item to it.

There is no range checking taking place.
If your words[x] array only has 5 words, but you still try to take word number 17 out of it you would expect an error.
Oct 11 '08 #3

Post your reply

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

Similar topics

reply views Thread by Yves Royer | last post: by
reply views Thread by Yves Royer | last post: by
6 posts views Thread by ltt19 | last post: by
5 posts views Thread by =?Utf-8?B?cGV0ZTE5Njk=?= | last post: by
omerbutt
3 posts views Thread by omerbutt | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.