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. Data that contains extra spaces

Data that contains extra spaces

Scheduled Pinned Locked Moved ASP.NET
question
13 Posts 4 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.
  • M Offline
    M Offline
    mayl
    wrote on last edited by
    #1

    Hi I'm trying to populate a datagrid with records that contains spaces. Ex: I have a record that has a value of "Contain Three spaces". However, when it binds, it shows up as "Contain Three spaces". Any ideas? Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here grddatabind() End Sub Sub grddatabind() Dim strConn As String = ConfigurationSettings.AppSettings("CONN_STR") Dim objOraConn As New OracleConnection(strConn) Dim objDV As DataView Dim objDS As New DataSet Dim objOraCmd As OracleCommand Dim objOraAdapter As OracleDataAdapter Dim sqlStr As String sqlStr = "select * from table" Try objOraCmd = New OracleCommand(sqlStr, objOraConn) objOraAdapter = New OracleDataAdapter(objOraCmd) objOraConn.Open() objOraAdapter.Fill(objDS) objDV = New DataView(objDS.Tables(0)) Me.DataGrid1.DataSource = objDV Me.DataGrid1.DataBind() Catch ex As Exception Finally If objOraConn.State = ConnectionState.Open Then objOraConn.Close() End If End Try End Sub thank you

    M J 3 Replies Last reply
    0
    • M mayl

      Hi I'm trying to populate a datagrid with records that contains spaces. Ex: I have a record that has a value of "Contain Three spaces". However, when it binds, it shows up as "Contain Three spaces". Any ideas? Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here grddatabind() End Sub Sub grddatabind() Dim strConn As String = ConfigurationSettings.AppSettings("CONN_STR") Dim objOraConn As New OracleConnection(strConn) Dim objDV As DataView Dim objDS As New DataSet Dim objOraCmd As OracleCommand Dim objOraAdapter As OracleDataAdapter Dim sqlStr As String sqlStr = "select * from table" Try objOraCmd = New OracleCommand(sqlStr, objOraConn) objOraAdapter = New OracleDataAdapter(objOraCmd) objOraConn.Open() objOraAdapter.Fill(objDS) objDV = New DataView(objDS.Tables(0)) Me.DataGrid1.DataSource = objDV Me.DataGrid1.DataBind() Catch ex As Exception Finally If objOraConn.State = ConnectionState.Open Then objOraConn.Close() End If End Try End Sub thank you

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      mayl wrote:

      I'm trying to populate a datagrid with records that contains spaces. Ex: I have a record that has a value of "Contain Three spaces". However, when it binds, it shows up as "Contain Three spaces". Any ideas?

      Um... if the field contains "Contain Three spaces", and it's displaying in your DataGrid as "Contain Three spaces", what exactly is the problem?

      M 1 Reply Last reply
      0
      • M mayl

        Hi I'm trying to populate a datagrid with records that contains spaces. Ex: I have a record that has a value of "Contain Three spaces". However, when it binds, it shows up as "Contain Three spaces". Any ideas? Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here grddatabind() End Sub Sub grddatabind() Dim strConn As String = ConfigurationSettings.AppSettings("CONN_STR") Dim objOraConn As New OracleConnection(strConn) Dim objDV As DataView Dim objDS As New DataSet Dim objOraCmd As OracleCommand Dim objOraAdapter As OracleDataAdapter Dim sqlStr As String sqlStr = "select * from table" Try objOraCmd = New OracleCommand(sqlStr, objOraConn) objOraAdapter = New OracleDataAdapter(objOraCmd) objOraConn.Open() objOraAdapter.Fill(objDS) objDV = New DataView(objDS.Tables(0)) Me.DataGrid1.DataSource = objDV Me.DataGrid1.DataBind() Catch ex As Exception Finally If objOraConn.State = ConnectionState.Open Then objOraConn.Close() End If End Try End Sub thank you

        J Offline
        J Offline
        Jakob Farian Krarup
        wrote on last edited by
        #3

        Hi Mayl :) Did you want the datagrid to discard the extra spaces, so no matter how many spaces there are, then it should only display one space...? Kind regards - Jakob :cool: ********************************************* Three kinds of people in the world: - Those who can count.. - Those who can't! 10 kinds of people in the world: - Those who understand binary - Those who don't

        M 1 Reply Last reply
        0
        • J Jakob Farian Krarup

          Hi Mayl :) Did you want the datagrid to discard the extra spaces, so no matter how many spaces there are, then it should only display one space...? Kind regards - Jakob :cool: ********************************************* Three kinds of people in the world: - Those who can count.. - Those who can't! 10 kinds of people in the world: - Those who understand binary - Those who don't

          M Offline
          M Offline
          mayl
          wrote on last edited by
          #4

          I want the datagrid to display all the spaces. thank you

          1 Reply Last reply
          0
          • M Mike Ellison

            mayl wrote:

            I'm trying to populate a datagrid with records that contains spaces. Ex: I have a record that has a value of "Contain Three spaces". However, when it binds, it shows up as "Contain Three spaces". Any ideas?

            Um... if the field contains "Contain Three spaces", and it's displaying in your DataGrid as "Contain Three spaces", what exactly is the problem?

            M Offline
            M Offline
            mayl
            wrote on last edited by
            #5

            "Contain Three spaces" There are 3 spaces between the word 'Three' and 'spaces'. thank you

            M 1 Reply Last reply
            0
            • M mayl

              "Contain Three spaces" There are 3 spaces between the word 'Three' and 'spaces'. thank you

              M Offline
              M Offline
              Mike Ellison
              wrote on last edited by
              #6

              I get it now :) It's standard behavior in a browser to compress your three spaces as one (which is what it has done in your posts, too). My guess is that if you view the resulting page source in your browser, the values have been outputted with the three spaces. To ensure literal spaces, you can use the entity   (non-breaking space). You might want to use a custom function in your grid column's ItemTemplate that would replace a " " character with " ".

              M 1 Reply Last reply
              0
              • M mayl

                Hi I'm trying to populate a datagrid with records that contains spaces. Ex: I have a record that has a value of "Contain Three spaces". However, when it binds, it shows up as "Contain Three spaces". Any ideas? Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here grddatabind() End Sub Sub grddatabind() Dim strConn As String = ConfigurationSettings.AppSettings("CONN_STR") Dim objOraConn As New OracleConnection(strConn) Dim objDV As DataView Dim objDS As New DataSet Dim objOraCmd As OracleCommand Dim objOraAdapter As OracleDataAdapter Dim sqlStr As String sqlStr = "select * from table" Try objOraCmd = New OracleCommand(sqlStr, objOraConn) objOraAdapter = New OracleDataAdapter(objOraCmd) objOraConn.Open() objOraAdapter.Fill(objDS) objDV = New DataView(objDS.Tables(0)) Me.DataGrid1.DataSource = objDV Me.DataGrid1.DataBind() Catch ex As Exception Finally If objOraConn.State = ConnectionState.Open Then objOraConn.Close() End If End Try End Sub thank you

                J Offline
                J Offline
                Jakob Farian Krarup
                wrote on last edited by
                #7

                If you want the DataGrid to display all the spaces, then subscribe to the DataGrid's ItemDataBound event, and add code like this:

                private void dgSampleSort_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
                {
                e.Item.Cells[0].Text = e.Item.Cells[0].Text.Replace(Environment.NewLine, " ");
                }

                Kind regards - Jakob :cool: ********************************************* Three kinds of people in the world: - Those who can count.. - Those who can't! 10 kinds of people in the world: - Those who understand binary - Those who don't

                M 1 Reply Last reply
                0
                • M Mike Ellison

                  I get it now :) It's standard behavior in a browser to compress your three spaces as one (which is what it has done in your posts, too). My guess is that if you view the resulting page source in your browser, the values have been outputted with the three spaces. To ensure literal spaces, you can use the entity   (non-breaking space). You might want to use a custom function in your grid column's ItemTemplate that would replace a " " character with " ".

                  M Offline
                  M Offline
                  mayl
                  wrote on last edited by
                  #8

                  Hi Mike I had modified my sql statement - select replace(filename, ' ',' ') from table It displays the extra spaces correctly, however, my datagrid does not wrap (I have ItemStyle-Wrap="True"). Any ideas? thank you

                  M M 2 Replies Last reply
                  0
                  • J Jakob Farian Krarup

                    If you want the DataGrid to display all the spaces, then subscribe to the DataGrid's ItemDataBound event, and add code like this:

                    private void dgSampleSort_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
                    {
                    e.Item.Cells[0].Text = e.Item.Cells[0].Text.Replace(Environment.NewLine, " ");
                    }

                    Kind regards - Jakob :cool: ********************************************* Three kinds of people in the world: - Those who can count.. - Those who can't! 10 kinds of people in the world: - Those who understand binary - Those who don't

                    M Offline
                    M Offline
                    mayl
                    wrote on last edited by
                    #9

                    Hi I added it but it didn't work. so I changed my sql statement (select replace(file_name, ' ',' ') from table) and it worked. However, the datagrid does not wrapped even though I have ItemStyle-Wrap="True". Any ideas? thank you

                    J 1 Reply Last reply
                    0
                    • M mayl

                      Hi Mike I had modified my sql statement - select replace(filename, ' ',' ') from table It displays the extra spaces correctly, however, my datagrid does not wrap (I have ItemStyle-Wrap="True"). Any ideas? thank you

                      M Offline
                      M Offline
                      Mike Ellison
                      wrote on last edited by
                      #10

                      Hmmm... yea, it wouldn't wrap because   is a non-breaking space... Well, one more thing you could try is to use your spaces as they are (no replacement for  's) and surround the value in a <span style="white-space: pre;"> tag or style="white-space: pre-wrap". I'm not sure what the browser support for the white-space style attribute is though.

                      1 Reply Last reply
                      0
                      • M mayl

                        Hi Mike I had modified my sql statement - select replace(filename, ' ',' ') from table It displays the extra spaces correctly, however, my datagrid does not wrap (I have ItemStyle-Wrap="True"). Any ideas? thank you

                        M Offline
                        M Offline
                        minhpc_bk
                        wrote on last edited by
                        #11

                        Like Mike said, the &nbsp; is a non-breaking space, so you don't replace all the spaces, but you may try replacing one in every two spaces. It means, if you have 3 spaces, the result after replace will look like the "[space]&nbsp;[space]"

                        1 Reply Last reply
                        0
                        • M mayl

                          Hi I added it but it didn't work. so I changed my sql statement (select replace(file_name, ' ',' ') from table) and it worked. However, the datagrid does not wrapped even though I have ItemStyle-Wrap="True". Any ideas? thank you

                          J Offline
                          J Offline
                          Jakob Farian Krarup
                          wrote on last edited by
                          #12

                          Do you have fixed width on the columns? That may help to force a linebreak. Kind regards - Jakob :cool: ********************************************* Three kinds of people in the world: - Those who can count.. - Those who can't! 10 kinds of people in the world: - Those who understand binary - Those who don't

                          M 1 Reply Last reply
                          0
                          • J Jakob Farian Krarup

                            Do you have fixed width on the columns? That may help to force a linebreak. Kind regards - Jakob :cool: ********************************************* Three kinds of people in the world: - Those who can count.. - Those who can't! 10 kinds of people in the world: - Those who understand binary - Those who don't

                            M Offline
                            M Offline
                            mayl
                            wrote on last edited by
                            #13

                            Yes I do, but it didn't wrap. thanks

                            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