Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Iam trying to minimize the lenhth of sting when binding to gridview it is working, but when iam trying to export to excel sheet it is not showing complete text rather it show "Sampletext....." Like this,

Please help to sort it out.
Posted
Comments
Kuthuparakkal 13-Feb-15 7:50am    
Need more info. How do you minimize string ?
Baroor 13-Feb-15 7:53am    
minimizing means showing text as "THIs IS S.." instead of "THIS IS SAMPLE QUESTION"

in grid view.
ZurdoDev 13-Feb-15 7:53am    
It's because you wrote code to make it do that.

You need to export the source of the grid rather than the grid itself. The datasource will contain the entire content.
 
Share this answer
 
Don't truncate the string; use CSS to hide the overflow instead.

ASPX file:
ASP.NET
<asp:TemplateField ItemStyle-CssClass="hide-overflow">
<ItemTemplate>
    <asp:Label runat="server"
        Text='<% Eval("DataItem.SKILLS") %>'
        ToolTip='<% Eval("DataItem.SKILLS") %>'
    />
</ItemTemplate>
</asp:TemplateField>


Stylesheet:
CSS
.hide-overflow
{
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
 
Share this answer
 
v2
Below is the code which solve your query,
string str="SampleText"
if (str.Length > 5)
str= str.Substring(0, 5) + "...";



Then out will be Sampl...
 
Share this answer
 
Comments
Baroor 13-Feb-15 8:03am    
By This i got Expected result in grid view, But when Exported to excel showing the text fallowed by ... only, rather i want complete text in excel column.



I Used This.

Text=' <%#DataBinder.Eval(Container,"DataItem.SKILLS").ToString().Length>15? DataBinder.Eval(Container,"DataItem.SKILLS").ToString().Substring(0,14)+"...":DataBinder.Eval(Container,"DataItem.SKILLS")%>' ToolTip='%#DataBinder.Eval(Container,"DataItem.SKILLS")'>
deepankarbhatnagar 15-Feb-15 23:55pm    
This code works correctly in my side, I am using it in my project, use your atic wit slightly, logic is this only.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900