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. retrieve the cell value from the gridview but it returns null

retrieve the cell value from the gridview but it returns null

Scheduled Pinned Locked Moved ASP.NET
helpdatabase
18 Posts 7 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.
  • C Christian Graus

    Is your page load interacting with your grid at all ? If you look at this code in the debugger, do any of the cells have data for that row ? For any row ? Tell me it's not really called gridview1 ???

    Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.

    K Offline
    K Offline
    kimo code
    wrote on last edited by
    #3

    my friend Christian :rose:; I have a user controle which carry this gridview and use it in the aspx page is this case cause any problem i dont know where is the error and why it carry null :(( :(( :confused:

    Kareem Elhosseny

    C 1 Reply Last reply
    0
    • C Christian Graus

      Is your page load interacting with your grid at all ? If you look at this code in the debugger, do any of the cells have data for that row ? For any row ? Tell me it's not really called gridview1 ???

      Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #4

      Christian Graus wrote:

      Tell me it's not really called gridview1 ???

      :) . Last week I was invited to one company for checking their code and giving some advice for their project. I can see a gridview named as gridView256 ! The page which they wrote contained 256 gridviews and all named like gridview1 .. 256. What a disaster !

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

      B 1 Reply Last reply
      0
      • K kimo code

        hi all, I just want to retrieve the cell value from the gridview using the following code,but it returns nothing null plz help me protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int index = e.RowIndex; //here to delete in data base //the problem in the next code this string (spareid)carry null string spareid = GridView1.Rows[index].Cells[0].ToString(); new DataAccess.Service().SparePart_Delete(spareid); //here to delete in dataset to reflect in gridview DataSet ds = (DataSet)Session["dataset"]; ds.Tables[0].Rows[index].Delete(); GridView1.DataSource = ds; GridView1.DataBind(); //here notification for delete lblmsg.Text = "delete ok "; lblmsg.Visible = true; } plz help me i dont know where is the error thanks in advice

        Kareem Elhosseny

        M Offline
        M Offline
        Masood Kochi SSF
        wrote on last edited by
        #5

        I also face that type problem. at that time i change the cell index even the original cell index is =0, Try this ..

        1 Reply Last reply
        0
        • K kimo code

          my friend Christian :rose:; I have a user controle which carry this gridview and use it in the aspx page is this case cause any problem i dont know where is the error and why it carry null :(( :(( :confused:

          Kareem Elhosseny

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #6

          No, that won't cause it, perhaps you could answer my questions ?

          Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.

          K 1 Reply Last reply
          0
          • K kimo code

            hi all, I just want to retrieve the cell value from the gridview using the following code,but it returns nothing null plz help me protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int index = e.RowIndex; //here to delete in data base //the problem in the next code this string (spareid)carry null string spareid = GridView1.Rows[index].Cells[0].ToString(); new DataAccess.Service().SparePart_Delete(spareid); //here to delete in dataset to reflect in gridview DataSet ds = (DataSet)Session["dataset"]; ds.Tables[0].Rows[index].Delete(); GridView1.DataSource = ds; GridView1.DataBind(); //here notification for delete lblmsg.Text = "delete ok "; lblmsg.Visible = true; } plz help me i dont know where is the error thanks in advice

            Kareem Elhosseny

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #7

            Are you binding the grid in the page load ? make sure you are doing it inside "!IsPostBack" blocks.

            elhosseny wrote:

            string spareid = GridView1.Rows[index].Cells[0].ToString();

            It's not safe to do the above. "Rows[index]" returns a row instance which may be NULL or the cell may be NULL. Check it is NULL, if not proceed with delete.

            All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

            K 1 Reply Last reply
            0
            • N N a v a n e e t h

              Christian Graus wrote:

              Tell me it's not really called gridview1 ???

              :) . Last week I was invited to one company for checking their code and giving some advice for their project. I can see a gridview named as gridView256 ! The page which they wrote contained 256 gridviews and all named like gridview1 .. 256. What a disaster !

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

              B Offline
              B Offline
              brettokumar
              wrote on last edited by
              #8

              im not using any server controls

              with regards, bretto

              1 Reply Last reply
              0
              • N N a v a n e e t h

                Are you binding the grid in the page load ? make sure you are doing it inside "!IsPostBack" blocks.

                elhosseny wrote:

                string spareid = GridView1.Rows[index].Cells[0].ToString();

                It's not safe to do the above. "Rows[index]" returns a row instance which may be NULL or the cell may be NULL. Check it is NULL, if not proceed with delete.

                All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                K Offline
                K Offline
                kimo code
                wrote on last edited by
                #9

                ok i'll change the gridview name is it the solve for my problem where the solution ???????????????????????????????????????????????????????????????????????????????????????

                Kareem Elhosseny

                B C 2 Replies Last reply
                0
                • K kimo code

                  ok i'll change the gridview name is it the solve for my problem where the solution ???????????????????????????????????????????????????????????????????????????????????????

                  Kareem Elhosseny

                  B Offline
                  B Offline
                  Bharani_Ram
                  wrote on last edited by
                  #10

                  Try This String Str = GridView1.Rows[e.RowIndex].Cells[0].Text;

                  Bharani

                  K 1 Reply Last reply
                  0
                  • C Christian Graus

                    No, that won't cause it, perhaps you could answer my questions ?

                    Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.

                    K Offline
                    K Offline
                    kimo code
                    wrote on last edited by
                    #11

                    Dear friend; my question why the cell carry null value ? i make all solution but it also carry null

                    Kareem Elhosseny

                    C 1 Reply Last reply
                    0
                    • B Bharani_Ram

                      Try This String Str = GridView1.Rows[e.RowIndex].Cells[0].Text;

                      Bharani

                      K Offline
                      K Offline
                      kimo code
                      wrote on last edited by
                      #12

                      my brother i make exactelly this code

                      Kareem Elhosseny

                      K 1 Reply Last reply
                      0
                      • K kimo code

                        my brother i make exactelly this code

                        Kareem Elhosseny

                        K Offline
                        K Offline
                        kimo code
                        wrote on last edited by
                        #13

                        is there a problem when i make all column as a templet filed is this make the problem

                        Kareem Elhosseny

                        B 1 Reply Last reply
                        0
                        • K kimo code

                          is there a problem when i make all column as a templet filed is this make the problem

                          Kareem Elhosseny

                          B Offline
                          B Offline
                          Bharani_Ram
                          wrote on last edited by
                          #14

                          No, There wont be any problem if u Made all the field to be template

                          Bharani

                          1 Reply Last reply
                          0
                          • K kimo code

                            Dear friend; my question why the cell carry null value ? i make all solution but it also carry null

                            Kareem Elhosseny

                            C Offline
                            C Offline
                            Christian Graus
                            wrote on last edited by
                            #15

                            I can't answer you, because I asked you questions to try to work out the problem and you did not answer them.

                            Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.

                            1 Reply Last reply
                            0
                            • K kimo code

                              ok i'll change the gridview name is it the solve for my problem where the solution ???????????????????????????????????????????????????????????????????????????????????????

                              Kareem Elhosseny

                              C Offline
                              C Offline
                              Christian Graus
                              wrote on last edited by
                              #16

                              The name just makes your code readable, it plainly won't solve the issue

                              Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.

                              K 1 Reply Last reply
                              0
                              • C Christian Graus

                                The name just makes your code readable, it plainly won't solve the issue

                                Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.

                                K Offline
                                K Offline
                                kimo code
                                wrote on last edited by
                                #17

                                I know i spend more time in this problem and i dont know where is the error here is my code again the cell value return null again where is the problem protected void grdSparepart_RowDeleting(object sender, GridViewDeleteEventArgs e) { //my problem here the string be null WHY??????????? :(( string spareid = grdSparepart.Rows[e.RowIndex].Cells[0].Text; :(( new DataAccess.Service().SparePart_Delete(spareid); DataSet ds = (DataSet)Session["dataset"]; ds.Tables[0].Rows[e.RowIndex].Delete(); grdSparepart.DataSource = ds; grdSparepart.DataBind(); lblmsg.Text = "delete ok "; lblmsg.Visible = true; }

                                Kareem Elhosseny

                                1 Reply Last reply
                                0
                                • K kimo code

                                  hi all, I just want to retrieve the cell value from the gridview using the following code,but it returns nothing null plz help me protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int index = e.RowIndex; //here to delete in data base //the problem in the next code this string (spareid)carry null string spareid = GridView1.Rows[index].Cells[0].ToString(); new DataAccess.Service().SparePart_Delete(spareid); //here to delete in dataset to reflect in gridview DataSet ds = (DataSet)Session["dataset"]; ds.Tables[0].Rows[index].Delete(); GridView1.DataSource = ds; GridView1.DataBind(); //here notification for delete lblmsg.Text = "delete ok "; lblmsg.Visible = true; } plz help me i dont know where is the error thanks in advice

                                  Kareem Elhosseny

                                  H Offline
                                  H Offline
                                  Herman T Instance
                                  wrote on last edited by
                                  #18

                                  If you have DataKey attribute set of your GridView then you know: GridView1.SelectedIndex = e.RowIndex; In that case you know the GridView1.SelectedValue and that is your DataKey. With that value you can do a delete in the database and after that reload your DataSet ds and Databind() it to GridView1. Have Fun

                                  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