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. Cells(2).Text returns an empty string

Cells(2).Text returns an empty string

Scheduled Pinned Locked Moved ASP.NET
javascriptdesigndebuggingquestion
8 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.
  • H Offline
    H Offline
    Hampden Tech
    wrote on last edited by
    #1

    I have the following code in my application... Protected Sub gridTerms_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridTerms.RowDataBound Dim strMsg As String If (e.Row.RowType = DataControlRowType.DataRow) Then If (e.Row.FindControl("lnkDelete") IsNot Nothing) Then strMsg = "return confirm('Please confirm. Delete payment term " & Trim(e.Row.Cells(2).Text) & "?');" CType(e.Row.FindControl("lnkDelete"), LinkButton).OnClientClick = strMsg End If End If End Sub For some reason the contents of this cell (which is a code) appears blank in the debugger and the JavaScript confirm shows an empty string in the message. The GridView appears fine but even investigating the value of e.Row.Cells(2).Text in the debugger reveals an empty string. Any ideas??

    K M A 3 Replies Last reply
    0
    • H Hampden Tech

      I have the following code in my application... Protected Sub gridTerms_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridTerms.RowDataBound Dim strMsg As String If (e.Row.RowType = DataControlRowType.DataRow) Then If (e.Row.FindControl("lnkDelete") IsNot Nothing) Then strMsg = "return confirm('Please confirm. Delete payment term " & Trim(e.Row.Cells(2).Text) & "?');" CType(e.Row.FindControl("lnkDelete"), LinkButton).OnClientClick = strMsg End If End If End Sub For some reason the contents of this cell (which is a code) appears blank in the debugger and the JavaScript confirm shows an empty string in the message. The GridView appears fine but even investigating the value of e.Row.Cells(2).Text in the debugger reveals an empty string. Any ideas??

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      In my experience with this stuff, sometimes you get literal controls inbetween your actual controls in the cell. I am guessing that your text might be in cells(3) instead of cells(2). Just a stab in the dark. Hope that helps. Ben

      H 1 Reply Last reply
      0
      • K kubben

        In my experience with this stuff, sometimes you get literal controls inbetween your actual controls in the cell. I am guessing that your text might be in cells(3) instead of cells(2). Just a stab in the dark. Hope that helps. Ben

        H Offline
        H Offline
        Hampden Tech
        wrote on last edited by
        #3

        Thanks for the reply. Actually, I investigated cells (0) through (4) in the debugger. All show empty strings, yet the GridView is populated with the propery data. This seems like it should be a no-brainer so it's really puzzling.

        K 1 Reply Last reply
        0
        • H Hampden Tech

          Thanks for the reply. Actually, I investigated cells (0) through (4) in the debugger. All show empty strings, yet the GridView is populated with the propery data. This seems like it should be a no-brainer so it's really puzzling.

          K Offline
          K Offline
          kubben
          wrote on last edited by
          #4

          You know when I have added confirm javascript type stuff to delete buttons, I have used a For Each loop in the gridview databound event. That way I can go through each datarow find the control and add the javascript. That sort of seems like what you are trying to do. Hope that helps. Ben

          1 Reply Last reply
          0
          • H Hampden Tech

            I have the following code in my application... Protected Sub gridTerms_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridTerms.RowDataBound Dim strMsg As String If (e.Row.RowType = DataControlRowType.DataRow) Then If (e.Row.FindControl("lnkDelete") IsNot Nothing) Then strMsg = "return confirm('Please confirm. Delete payment term " & Trim(e.Row.Cells(2).Text) & "?');" CType(e.Row.FindControl("lnkDelete"), LinkButton).OnClientClick = strMsg End If End If End Sub For some reason the contents of this cell (which is a code) appears blank in the debugger and the JavaScript confirm shows an empty string in the message. The GridView appears fine but even investigating the value of e.Row.Cells(2).Text in the debugger reveals an empty string. Any ideas??

            M Offline
            M Offline
            Marcus J Smith
            wrote on last edited by
            #5

            Is this formatted text? I always had trouble getting the value from the cells that contained formatted text, maybe you should try to get the innerHTML.


            Cleako

            1 Reply Last reply
            0
            • H Hampden Tech

              I have the following code in my application... Protected Sub gridTerms_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridTerms.RowDataBound Dim strMsg As String If (e.Row.RowType = DataControlRowType.DataRow) Then If (e.Row.FindControl("lnkDelete") IsNot Nothing) Then strMsg = "return confirm('Please confirm. Delete payment term " & Trim(e.Row.Cells(2).Text) & "?');" CType(e.Row.FindControl("lnkDelete"), LinkButton).OnClientClick = strMsg End If End If End Sub For some reason the contents of this cell (which is a code) appears blank in the debugger and the JavaScript confirm shows an empty string in the message. The GridView appears fine but even investigating the value of e.Row.Cells(2).Text in the debugger reveals an empty string. Any ideas??

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

              Hai, what the method you are doing is correct. the same logic is to be used after the data binding of grid and not in the databound or row databound event. this way... foreach (DataGridItem dgi in dg.Items) { // do the needed logic here } really it works. Cheers asithangae

              M 1 Reply Last reply
              0
              • A asithangae

                Hai, what the method you are doing is correct. the same logic is to be used after the data binding of grid and not in the databound or row databound event. this way... foreach (DataGridItem dgi in dg.Items) { // do the needed logic here } really it works. Cheers asithangae

                M Offline
                M Offline
                Marcus J Smith
                wrote on last edited by
                #7

                If it is working why would he be posting a question?


                Cleako

                A 1 Reply Last reply
                0
                • M Marcus J Smith

                  If it is working why would he be posting a question?


                  Cleako

                  A Offline
                  A Offline
                  asithangae
                  wrote on last edited by
                  #8

                  He use this logic in rowdatabound event, i asked him to do the same after databind. i think you can know the difference. Cheers asithangae

                  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