Using checkbox in autogenerated datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashasprabhu
    New Member
    • Jan 2007
    • 52

    Using checkbox in autogenerated datagrid

    hi all,
    I have 3 autogenerated columns and 1 template column for checkbox and im using vs 2003 in asp.net
    my code is
    Code:
            Dim myDataGridItem As DataGridItem
            Dim chkSelected As New System.Web.UI.WebControls.CheckBox
                    For Each myDataGridItem In dgresult.Items
             chkSelected = myDataGridItem.FindControl("chkSelection")    
           If chkSelected.Checked Then
                    If dgresult.Items.Count Mod dgresult.PageSize = 1 And _
      dgresult.CurrentPageIndex = dgresult.PageCount - 1 And _
      dgresult.CurrentPageIndex <> 0 Then
                        dgresult.CurrentPageIndex = dgresult.CurrentPageIndex - 1
                    End If
                    'update command
                End If
                        Next
    chkSelected returns false and the command does not execute
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Which event are you using?

    Comment

    • ashasprabhu
      New Member
      • Jan 2007
      • 52

      #3
      Originally posted by kenobewan
      Which event are you using?
      im using onclick event of update button

      Comment

      • altafhussain
        New Member
        • Jun 2007
        • 4

        #4
        Originally posted by ashasprabhu
        hi all,
        I have 3 autogenerated columns and 1 template column for checkbox and im using vs 2003 in asp.net
        my code is
        Code:
                Dim myDataGridItem As DataGridItem
                Dim chkSelected As New System.Web.UI.WebControls.CheckBox
                        For Each myDataGridItem In dgresult.Items
                 chkSelected = myDataGridItem.FindControl("chkSelection")    
               If chkSelected.Checked Then
                        If dgresult.Items.Count Mod dgresult.PageSize = 1 And _
          dgresult.CurrentPageIndex = dgresult.PageCount - 1 And _
          dgresult.CurrentPageIndex <> 0 Then
                            dgresult.CurrentPageIndex = dgresult.CurrentPageIndex - 1
                        End If
                        'update command
                    End If
                            Next
        chkSelected returns false and the command does not execute

        Hi

        Check whether you have written ! Ispostback ! in the page load.
        Because whenever you click a button, it postbacks and the checkbox you have selected became unchecked and hence it will return false


        Please check this link
        http://aspalliance.com/136_DataGrid_an d_Checkboxes

        Comment

        • ashasprabhu
          New Member
          • Jan 2007
          • 52

          #5
          Originally posted by altafhussain
          Hi

          Check whether you have written ! Ispostback ! in the page load.
          Because whenever you click a button, it postbacks and the checkbox you have selected became unchecked and hence it will return false


          Please check this link
          http://aspalliance.com/136_DataGrid_an d_Checkboxes
          hi,
          thankyou very...much hussain,
          actually i have copied code from the same article
          My doubt is after selecting the rows only i click the button then where to store the status of the checkbox and how to use those values

          Comment

          • altafhussain
            New Member
            • Jun 2007
            • 4

            #6
            Originally posted by ashasprabhu
            hi,
            thankyou very...much hussain,
            actually i have copied code from the same article
            My doubt is after selecting the rows only i click the button then where to store the status of the checkbox and how to use those values

            Hi Prabhu

            If you click "Click here to download the ASPX page", it will open a new window with this link "http://authors.aspalli ance.com/das/dg_checkbox.htm l" :)
            In this link there is a method name btnSelect_OnCli ck,

            you have to declare a variable inside this method and if u have to insert those checked records then you have a write a insert query inside of the for loop :)

            Comment

            • ashasprabhu
              New Member
              • Jan 2007
              • 52

              #7
              hi,
              i found that the pageload event was called twice which lead to the uncheck of the datagrid checkbox
              thank you all [:)]

              Comment

              Working...