grid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shalini166
    New Member
    • Apr 2008
    • 70

    grid

    how to select particular row in datagrid when checkbox in datagrid is selected and also inserted into database

    pls help me.it is need for my mca project.
  • vee10
    New Member
    • Oct 2006
    • 141

    #2
    u can check out this link

    http://www.codeproject .com/KB/webforms/datagridcheckbo x.aspx





    Originally posted by shalini166
    how to select particular row in datagrid when checkbox in datagrid is selected and also inserted into database

    pls help me.it is need for my mca project.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by shalini166
      how to select particular row in datagrid when checkbox in datagrid is selected and also inserted into database

      pls help me.it is need for my mca project.
      Add a CheckBox column to your grid.
      Then when you are ready to update your database, loop through your grid and determine which ones were selected...

      eg

      [code=vbnet]
      For Each row in MyGridView.Rows
      Dim chkBox as CheckBox = Ctype(row.FindC ontrol("nameOfM yCheckboxInTheG rid"),Checkbox )
      If chkBox.Checked = True
      'Do your update
      End If
      Next
      [/code]

      -Frinny

      Comment

      • shalini166
        New Member
        • Apr 2008
        • 70

        #4
        Hi,

        How to select particular row in datagrid when checkbox in datagrid is selected and also inserted into database.

        sorry for the disturbance.

        i need c# coding and also insert particular row coding.or multiple row insertion coding.

        pls help me.

        Comment

        • vee10
          New Member
          • Oct 2006
          • 141

          #5
          Hi,

          I think on checking the checkbox in the datagrid any of the events is going to fire so u should place a button and do the necessay thing u want to do

          if u get any solution plz share that




          Originally posted by shalini166
          Hi,

          How to select particular row in datagrid when checkbox in datagrid is selected and also inserted into database.

          sorry for the disturbance.

          i need c# coding and also insert particular row coding.or multiple row insertion coding.

          pls help me.

          Comment

          • shalini166
            New Member
            • Apr 2008
            • 70

            #6
            i want to know how to insert each cell in the datagrid to the database.

            pls help me.

            Comment

            • vee10
              New Member
              • Oct 2006
              • 141

              #7
              hi..

              Code:
                      
                      SqlConnection conn = new SqlConnection("Data Source=PRAVEENAPC;Initial Catalog=testing;Integrated Security=True");
                      conn.Open();
                      SqlCommand cmd = new SqlCommand();
                      cmd.CommandText = "insert into emp values(";
                      cmd.Connection = conn;
                      for (int i = 0; i < GridView1.Columns.Count; i++)
                      {
                          cmd.CommandText  = cmd.CommandText + "'" + GridView1.Rows[0].Cells[i].Text + "'";
                          if (i + 1 != GridView1.Columns.Count)
                              cmd.CommandText = cmd.CommandText + ",";
                                }
              
                      cmd.CommandText = cmd.CommandText + ")";
              
                      int insert=cmd.ExecuteNonQuery();
              this is one way of inserting the values into database

              there are other way using parameter etc.....
              but this is how u can retrieve the rows in database


              Originally posted by shalini166
              i want to know how to insert each cell in the datagrid to the database.

              pls help me.

              Comment

              Working...