Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Sir i m inserting my data in database. now i am retrieving it in a gridview. everything is ok, but i want to show the data (as description of any country) in size of 200px,2oopx. but the description is too large, and it is overlapping in other cells of next country description.
 
My code of gridview is as.
 
<asp:GridView ID="gridCountry" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:TemplateField>
                <HeaderTemplate>ID</HeaderTemplate>
                <ItemTemplate>
                    <asp:Label ID="grdlblID" runat="server" Text='<%# Eval("_COUNTRYID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>Country</HeaderTemplate>
                <ItemTemplate>
                    <asp:Label ID="grdlblCountry" runat="server" Text='<%# Eval("_COUNTRY") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>Flag</HeaderTemplate>
                <ItemTemplate>
                    <asp:Image runat="server" ImageUrl='<%# "~/Administrator/Images/" + Eval("_FLAG") %>' Width="50px" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>Continent</HeaderTemplate>
                <ItemTemplate>
                    <asp:Label ID="grdlblContinent" runat="server" Text='<%# Eval("_CONTINENT") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Visa Des
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:Label ID="grdlblVisa" runat="server" Text='<%# Eval("_VISA") %>' Width="150px" Height="150px"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Country Des
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:Label ID="grdlblCountryDes" runat="server" Text='<%# Eval("_ABOUTCOUNTRY") %>' Height="150px"  Width="150px"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Country Image 1
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:Image ID="grdimgCountry1" runat="server"  Width="150px" ImageUrl='<%# "~/Administrator/CountryImage/"+ Eval("_COUNTRYIMAGE1") %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    country Image 2
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:Image ID="grdimgCountry2" runat="server"  Width="150px" ImageUrl='<%# "~/Administrator/CountryImage/" + Eval("_COUNTRYIMAGE2") %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    created By
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:Label ID="grdlblCreatedBy" runat="server" Text='<%# Eval("_CREATEDBY") %> '></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    Created On
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:Label ID="grdlblCreatedOn" runat="server" Text='<%# Eval("_CREATEDON") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
 
        </Columns>
    </asp:GridView>
Posted 31-May-12 3:52am
manu027714
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can add
 
style="overflow:scroll"
or
style="overflow:hidden"
to your label
or add CssClass to your ItemTemplae
and set this style
  Permalink  
Comments
Sandeep Mewara at 31-May-12 16:08pm
   
5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
you can set class or style for your label.
Es:
<asp:label text="..." runat="server"
    style="width:200px; height:200px; white-space: nowrap(or normal); 
    overflow: hidden(or scroll)"
</asp:label>
 
otherwise
 
you can break you text in rowdatabound event:
<asp:label text='<%# breakMyString(Eval("_COUNTRY"), 60) %>' />
protected string breakMyString(string inString, int len)
{
    string outString = inString;
    string suffix = " more...";
    if (!string.IsNullOrEmpty(inString) && inString.Length > len)
        outString = string.Concat(inString.Substring(0, len - suffix.Length), suffix);
 
    return outString;
}
  Permalink  
v2
Comments
Sandeep Mewara at 31-May-12 16:08pm
   
5!

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

  Print Answers RSS
0 OriginalGriff 565
1 Maciej Los 319
2 Richard MacCutchan 220
3 BillWoodruff 164
4 Mathew Soji 160
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 31 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100