Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Set the Max character length in Grid column

Set the Max character length in Grid column

Scheduled Pinned Locked Moved ASP.NET
css
9 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vid nandha
    wrote on last edited by
    #1

    Hi to all, I want to display description like maximum 20 characters in grid column.....i have already used boundfield of grid to display the field Description..... i have tried to do it by Itemstyle but its not working.... can any one tell me the soluntion for that........ :(

    Q 1 Reply Last reply
    0
    • V vid nandha

      Hi to all, I want to display description like maximum 20 characters in grid column.....i have already used boundfield of grid to display the field Description..... i have tried to do it by Itemstyle but its not working.... can any one tell me the soluntion for that........ :(

      Q Offline
      Q Offline
      Qasim1984
      wrote on last edited by
      #2

      Can you show me Binding code?

      V 1 Reply Last reply
      0
      • Q Qasim1984

        Can you show me Binding code?

        V Offline
        V Offline
        vid nandha
        wrote on last edited by
        #3

        ya sure.........this is the code.... <asp:GridView ID="gvMenuCategory" runat="server" AutoGenerateColumns="False" AllowPaging="true" AllowSorting="true" PageSize="3" CssClass="datatable" OnPageIndexChanging="gvMenuCategory_PageIndexChanging" onrowdatabound="gvMenuCategory_RowDataBound"> <HeaderStyle HorizontalAlign="Left" CssClass="head" /> <Columns> <asp:BoundField HeaderText="Name" DataField="Name" ItemStyle-Width="30%" /> <asp:BoundField HeaderText="Description" ItemStyle-Width="60%" ItemStyle-Wrap="true" DataField="Description" /> <asp:HyperLinkField Text="Edit" DataNavigateUrlFormatString="/Menu/MenuCategory.aspx?Restaurant&MenuCategoryID={0}" DataNavigateUrlFields="MenuCategoryID" HeaderText="Edit"></asp:HyperLinkField> </Columns> <HeaderStyle BackColor="#6B696B" ForeColor="White" /> </asp:GridView> hope u will get idea by this..............

        Q 1 Reply Last reply
        0
        • V vid nandha

          ya sure.........this is the code.... <asp:GridView ID="gvMenuCategory" runat="server" AutoGenerateColumns="False" AllowPaging="true" AllowSorting="true" PageSize="3" CssClass="datatable" OnPageIndexChanging="gvMenuCategory_PageIndexChanging" onrowdatabound="gvMenuCategory_RowDataBound"> <HeaderStyle HorizontalAlign="Left" CssClass="head" /> <Columns> <asp:BoundField HeaderText="Name" DataField="Name" ItemStyle-Width="30%" /> <asp:BoundField HeaderText="Description" ItemStyle-Width="60%" ItemStyle-Wrap="true" DataField="Description" /> <asp:HyperLinkField Text="Edit" DataNavigateUrlFormatString="/Menu/MenuCategory.aspx?Restaurant&MenuCategoryID={0}" DataNavigateUrlFields="MenuCategoryID" HeaderText="Edit"></asp:HyperLinkField> </Columns> <HeaderStyle BackColor="#6B696B" ForeColor="White" /> </asp:GridView> hope u will get idea by this..............

          Q Offline
          Q Offline
          Qasim1984
          wrote on last edited by
          #4

          use the itemtemplate instead of BoundField like this one <Columns> <asp:BoundField HeaderText="Name" DataField="Name" ItemStyle-Width="30%" /> <asp:TemplateField > <ItemTemplate> <asp:Label id="lblDescription" Text='<%# Eval("Description") %>' /> </ItemTemplate> </asp:TemplateField> <asp:HyperLinkField Text="Edit" DataNavigateUrlFormatString="/Menu/MenuCategory.aspx?Restaurant&MenuCategoryID={0}" DataNavigateUrlFields="MenuCategoryID" HeaderText="Edit"></asp:HyperLinkField> </Columns> Then use the RowDataBound event of your gridview and code the following protected void gvMenuCategory_RowDataBound(object sender, GridViewRowEventArgs e) { string fulldesc=""; if(e.Row.RowType==DataControlRowType.DataRow) { DataRowView dr= (DataRowView)e.Row.DataItem; fulldesc=dr["Description"].ToString(); Label lbldesc = (Label)e.Row.FindControl("lblDescription"); lbldesc.Text = fulldesc.Substring(0, 19); } } Hope this work for you

          V 1 Reply Last reply
          0
          • Q Qasim1984

            use the itemtemplate instead of BoundField like this one <Columns> <asp:BoundField HeaderText="Name" DataField="Name" ItemStyle-Width="30%" /> <asp:TemplateField > <ItemTemplate> <asp:Label id="lblDescription" Text='<%# Eval("Description") %>' /> </ItemTemplate> </asp:TemplateField> <asp:HyperLinkField Text="Edit" DataNavigateUrlFormatString="/Menu/MenuCategory.aspx?Restaurant&MenuCategoryID={0}" DataNavigateUrlFields="MenuCategoryID" HeaderText="Edit"></asp:HyperLinkField> </Columns> Then use the RowDataBound event of your gridview and code the following protected void gvMenuCategory_RowDataBound(object sender, GridViewRowEventArgs e) { string fulldesc=""; if(e.Row.RowType==DataControlRowType.DataRow) { DataRowView dr= (DataRowView)e.Row.DataItem; fulldesc=dr["Description"].ToString(); Label lbldesc = (Label)e.Row.FindControl("lblDescription"); lbldesc.Text = fulldesc.Substring(0, 19); } } Hope this work for you

            V Offline
            V Offline
            vid nandha
            wrote on last edited by
            #5

            thanx for this code.............but before also i have already used that DataRowView but it gives error like "Unable to cast object of type 'repository of my project' to type 'System.Data.DataRowView'." though i tried your code but it gives still the same error......... if u have another solution then please tell me...........i m trying to solve it from 2 days...... thanx

            Q 1 Reply Last reply
            0
            • V vid nandha

              thanx for this code.............but before also i have already used that DataRowView but it gives error like "Unable to cast object of type 'repository of my project' to type 'System.Data.DataRowView'." though i tried your code but it gives still the same error......... if u have another solution then please tell me...........i m trying to solve it from 2 days...... thanx

              Q Offline
              Q Offline
              Qasim1984
              wrote on last edited by
              #6

              Send me your HTML, Code behind and also send complete exception that the page is throwing.

              V 1 Reply Last reply
              0
              • Q Qasim1984

                Send me your HTML, Code behind and also send complete exception that the page is throwing.

                V Offline
                V Offline
                vid nandha
                wrote on last edited by
                #7

                Thanx for yr precious time......but i got the solution of my problem now........ i need to write just 1 line code........in Boundfield of description in grid......... :) again very much thanx for showing interest on my Problem........

                V 1 Reply Last reply
                0
                • V vid nandha

                  Thanx for yr precious time......but i got the solution of my problem now........ i need to write just 1 line code........in Boundfield of description in grid......... :) again very much thanx for showing interest on my Problem........

                  V Offline
                  V Offline
                  vid nandha
                  wrote on last edited by
                  #8

                  and ya if u can help for another problem ......... the problem is i want to bind the static dropdownlist in Grid... like........in design aspx page.....code is like... <asp:DropDownList ID="ddlStatus" CssClass="Dropdown" runat="server"> <asp:ListItem Text="Available" Value="1"></asp:ListItem> <asp:ListItem Text="Seasonal" Value="2"></asp:ListItem> <asp:ListItem Text="Closed" Value="3"></asp:ListItem> </asp:DropDownList> now i wan to display text item in the grid that is "Available","Seasonal","Closed"... how can i display that item in grid...... if u know then give the solution...it will be helpful to me.........

                  V 1 Reply Last reply
                  0
                  • V vid nandha

                    and ya if u can help for another problem ......... the problem is i want to bind the static dropdownlist in Grid... like........in design aspx page.....code is like... <asp:DropDownList ID="ddlStatus" CssClass="Dropdown" runat="server"> <asp:ListItem Text="Available" Value="1"></asp:ListItem> <asp:ListItem Text="Seasonal" Value="2"></asp:ListItem> <asp:ListItem Text="Closed" Value="3"></asp:ListItem> </asp:DropDownList> now i wan to display text item in the grid that is "Available","Seasonal","Closed"... how can i display that item in grid...... if u know then give the solution...it will be helpful to me.........

                    V Offline
                    V Offline
                    vid nandha
                    wrote on last edited by
                    #9

                    and ya the status is integer in the database.....ok so i have that kind of problem.........otherwise it will be done by this... ddlStatus.selecteditem.text right?

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups