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
- <asp:TemplateField HeaderText="CommentText">
- <ItemTemplate>
- <asp:Labelid="lbl"text='<%#tooltip(System.Convert.ToString(Eval("CommentText"))) %>' runat="server" ToolTip='<%#Eval("CommentText") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
Expand|Select|Wrap|Line Numbers
- public string tooltip(String input)//function is to display only 1st 20characters
- {
- char[] delimiterChars = { ' ' };
- string[] words = input.Split(delimiterChars);
- string output = "";
- //rebuilds string without new word
- for (int x = 0; x != 20; x++)
- {
- if (x == 0)
- {
- output = words[x].ToString();
- }
- else
- {
- output = output+" "+words[x];
- }
- }
- return output;
- }
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
- Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.
- Source Error:
- Line 31: else
- Line 32: {
- Line 33: output = output+" "+words[x];
- Line 34: }
- Line 35: }
Thank You