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. GridView & CheckBox

GridView & CheckBox

Scheduled Pinned Locked Moved ASP.NET
helpdatabase
9 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.
  • C Offline
    C Offline
    comp_j
    wrote on last edited by
    #1

    Hello, Ive got a problem with Gridview! I want access to column's data that is checked. and I dont know why this code doesnt work. The value of "chbxRmove.Checked" always is False even when the column is checked !!! :(( plz help me. foreach (GridViewRowgridRowinthis.GridView1.Rows) { CheckBoxchbxRmove = (CheckBox)gridRow.FindControl("chkSelect"); if (chbxRmove.Checked) { //Row Index } }

    B A C B 4 Replies Last reply
    0
    • C comp_j

      Hello, Ive got a problem with Gridview! I want access to column's data that is checked. and I dont know why this code doesnt work. The value of "chbxRmove.Checked" always is False even when the column is checked !!! :(( plz help me. foreach (GridViewRowgridRowinthis.GridView1.Rows) { CheckBoxchbxRmove = (CheckBox)gridRow.FindControl("chkSelect"); if (chbxRmove.Checked) { //Row Index } }

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      Probably checkbox is losing state on load event of Page,check it carefully. By the way,if you had problems with internet connection then delete one post of your same question.


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

      C 1 Reply Last reply
      0
      • C comp_j

        Hello, Ive got a problem with Gridview! I want access to column's data that is checked. and I dont know why this code doesnt work. The value of "chbxRmove.Checked" always is False even when the column is checked !!! :(( plz help me. foreach (GridViewRowgridRowinthis.GridView1.Rows) { CheckBoxchbxRmove = (CheckBox)gridRow.FindControl("chkSelect"); if (chbxRmove.Checked) { //Row Index } }

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        I guess you are binding the Gridview data on Page_Load and you are not checking the Postback properties, which reset the Grid Check box field. Try this

        if(!Page.IsPostBack)
        {
        //BindGridViewData.
        }

        Hope this will help you. :-D

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

        C 1 Reply Last reply
        0
        • A Abhijit Jana

          I guess you are binding the Gridview data on Page_Load and you are not checking the Postback properties, which reset the Grid Check box field. Try this

          if(!Page.IsPostBack)
          {
          //BindGridViewData.
          }

          Hope this will help you. :-D

          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

          C Offline
          C Offline
          comp_j
          wrote on last edited by
          #4

          Thank u very very much :thumbsup:

          B 1 Reply Last reply
          0
          • C comp_j

            Thank u very very much :thumbsup:

            B Offline
            B Offline
            Blue_Boy
            wrote on last edited by
            #5

            And what is difference between my answer and Abhijit's answer?


            I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

            1 Reply Last reply
            0
            • B Blue_Boy

              Probably checkbox is losing state on load event of Page,check it carefully. By the way,if you had problems with internet connection then delete one post of your same question.


              I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

              C Offline
              C Offline
              comp_j
              wrote on last edited by
              #6

              I'm very grateful that you attended to my question :thumbsup: but Abhijit's answer was more comprehensive than your answer. :)

              1 Reply Last reply
              0
              • C comp_j

                Hello, Ive got a problem with Gridview! I want access to column's data that is checked. and I dont know why this code doesnt work. The value of "chbxRmove.Checked" always is False even when the column is checked !!! :(( plz help me. foreach (GridViewRowgridRowinthis.GridView1.Rows) { CheckBoxchbxRmove = (CheckBox)gridRow.FindControl("chkSelect"); if (chbxRmove.Checked) { //Row Index } }

                C Offline
                C Offline
                comp_j
                wrote on last edited by
                #7

                also I've anather question. :-D How do I get selected row's data (Like ID)?

                modified on Monday, July 27, 2009 4:46 PM

                A 1 Reply Last reply
                0
                • C comp_j

                  also I've anather question. :-D How do I get selected row's data (Like ID)?

                  modified on Monday, July 27, 2009 4:46 PM

                  A Offline
                  A Offline
                  Abhijit Jana
                  wrote on last edited by
                  #8

                  comp_j wrote:

                  How do am I get selected row's data (Like ID)?

                  There is a class GridViewRow, on SelectedIndexChnaged event of Grid, Read the current Selected Row in GridViewRow, then you can read each and every column from it. Even you can read directly the data.

                  protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
                  {
                  int ID= Int32.Parse(GridView1.Rows[GridView1.SelectedIndex].Cells[0].Text);
                  }

                  Note : I assume, Cell[0] of Grid contain your ID Hope this will help you :-D

                  Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

                  1 Reply Last reply
                  0
                  • C comp_j

                    Hello, Ive got a problem with Gridview! I want access to column's data that is checked. and I dont know why this code doesnt work. The value of "chbxRmove.Checked" always is False even when the column is checked !!! :(( plz help me. foreach (GridViewRowgridRowinthis.GridView1.Rows) { CheckBoxchbxRmove = (CheckBox)gridRow.FindControl("chkSelect"); if (chbxRmove.Checked) { //Row Index } }

                    B Offline
                    B Offline
                    bonypatel
                    wrote on last edited by
                    #9

                    foreach (GridViewRow gv in gvShowUser.Rows) { CheckBox chk = (CheckBox)gv.FindControl("chkEditUser"); if (chk.Checked) { //uid = ((Label)gv.FindControl("lblEditUserId")).Text.ToString(); //userid = Convert.ToInt32(uid); //cnt++; } }

                    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