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
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to make gridview column text no wrap and how to create a resizable column header

how to make gridview column text no wrap and how to create a resizable column header

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-nettutorial
8 Posts 2 Posters 0 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.
  • A Offline
    A Offline
    Andraw111
    wrote on last edited by
    #1

    Hi, all, I have create a gridview in asp.net with C#, there is a column called Project Name which sometimes has long text, now if it's longer then column width, it will wrap to two line, I don't like this, I want to hide the longer part, how can I do it?? The second question is how can I make gridview header column resizable? is it possible if don't use AJAX? Thanks! Andraw

    J 2 Replies Last reply
    0
    • A Andraw111

      Hi, all, I have create a gridview in asp.net with C#, there is a column called Project Name which sometimes has long text, now if it's longer then column width, it will wrap to two line, I don't like this, I want to hide the longer part, how can I do it?? The second question is how can I make gridview header column resizable? is it possible if don't use AJAX? Thanks! Andraw

      J Offline
      J Offline
      Jamil Hallal
      wrote on last edited by
      #2

      Hi Andraw, you can use the DataBound event of the Gridview as per the below code:

      protected void gvProjects_RowDataBound(object sender, GridViewRowEventArgs e)
      {
      string projectName = ((DataRowView)e.Row.DataItem)["ProjectName"].ToString();
      if (projectName.Length > 200)
      {
      projectName.Substring(0, 200);
      }
      }

      or you can loop over the list/DataTable (the Datasource) that you are using to bind your GridView and check the length of the project name and Substring it.

      Regards, Jamil

      A 1 Reply Last reply
      0
      • A Andraw111

        Hi, all, I have create a gridview in asp.net with C#, there is a column called Project Name which sometimes has long text, now if it's longer then column width, it will wrap to two line, I don't like this, I want to hide the longer part, how can I do it?? The second question is how can I make gridview header column resizable? is it possible if don't use AJAX? Thanks! Andraw

        J Offline
        J Offline
        Jamil Hallal
        wrote on last edited by
        #3

        as for resizing the column please check the following article: http://www.dotnetspider.com/resources/18257-Gridview-Resizable-column.aspx

        Regards, Jamil

        A 1 Reply Last reply
        0
        • J Jamil Hallal

          Hi Andraw, you can use the DataBound event of the Gridview as per the below code:

          protected void gvProjects_RowDataBound(object sender, GridViewRowEventArgs e)
          {
          string projectName = ((DataRowView)e.Row.DataItem)["ProjectName"].ToString();
          if (projectName.Length > 200)
          {
          projectName.Substring(0, 200);
          }
          }

          or you can loop over the list/DataTable (the Datasource) that you are using to bind your GridView and check the length of the project name and Substring it.

          Regards, Jamil

          A Offline
          A Offline
          Andraw111
          wrote on last edited by
          #4

          Hi, Jamil, Thanks for your reply. If I limited the text length, when I resize the column width, the cut part cannot be displayed, right? why doesn't work? I will try your link in the next reply.

          J 1 Reply Last reply
          0
          • A Andraw111

            Hi, Jamil, Thanks for your reply. If I limited the text length, when I resize the column width, the cut part cannot be displayed, right? why doesn't work? I will try your link in the next reply.

            J Offline
            J Offline
            Jamil Hallal
            wrote on last edited by
            #5

            yes , if you set the length of the text then when resizing the column the hidden part of the text will appear again because it is already rendered. This is totally related to the pattern of resizing that you are going to use.

            Regards, Jamil

            A 1 Reply Last reply
            0
            • J Jamil Hallal

              as for resizing the column please check the following article: http://www.dotnetspider.com/resources/18257-Gridview-Resizable-column.aspx

              Regards, Jamil

              A Offline
              A Offline
              Andraw111
              wrote on last edited by
              #6

              Hi, Jamil, I try the codes in your link, but it doesn't work for me, I don't know why. I have my gridview decalred as the following: also my page is web content page, I put the gridview in

              tag to create scroll bar and fixed the header while scroll, do these features affect the resizing? Thanks!

              1 Reply Last reply
              0
              • J Jamil Hallal

                yes , if you set the length of the text then when resizing the column the hidden part of the text will appear again because it is already rendered. This is totally related to the pattern of resizing that you are going to use.

                Regards, Jamil

                A Offline
                A Offline
                Andraw111
                wrote on last edited by
                #7

                But if we fixed the text length to 200, even the column is resized, we still cannot see the extra part, am I right?

                J 1 Reply Last reply
                0
                • A Andraw111

                  But if we fixed the text length to 200, even the column is resized, we still cannot see the extra part, am I right?

                  J Offline
                  J Offline
                  Jamil Hallal
                  wrote on last edited by
                  #8

                  yes you are 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