asp.net: how to update a checkbox in an editItemTemplate true or false

westdh
westdh used Ask the Experts™
on
how to update a checkbox in an editItemTemplate - true or false

<asp:TemplateField ItemStyle-Width="220" ItemStyle-BackColor = "#F4F4F4" ItemStyle-HorizontalAlign="Center" HeaderStyle-BackColor="#A1C1D9" HeaderStyle-Font-Size="9" HeaderText="IsActive">
                        <ItemTemplate>
                              <asp:CheckBox ID="lblIsActive" runat="server" Text='<%# DataBinder.Eval( Container.DataItem, "IsActive")%>' />
                        </ItemTemplate>
                        <EditItemTemplate>
                              <asp:CheckBox ID="lblIsActive" Checked='<%# Eval("IsActive") %>' runat="server" />
                        </EditItemTemplate>         
            </asp:TemplateField> Checkbox
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Also how to set it to true if 'isActive' = 'true'
Hello,

You have to find the checkbox id through for loop and then if comes true from database, it checked = true. Write the code for when the value comes true and false.

Author

Commented:
I am not in a loop: I am in a GridView row and the the Value is True. I want to edit it in EditItemTemplate. I want to set it false.
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Author

Commented:
Here is my update proc.

I can add this: ???

  Dim chkIsActive As CheckBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("chkIsActive")

what else:

what do I add in the sql update
Protected Sub uxItemDetailGrid_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)

        Dim lbl As Label = uxItemDetailGrid.Rows(e.RowIndex).FindControl("lblLocationID")
        Dim txttitle As TextBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("txtTitle")
        Dim FreeTextBox1 As FreeTextBoxControls.FreeTextBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("FreeTextBox1")
        Dim txtaddress As TextBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("txtAddress")
        Dim txtcity As TextBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("txtCity")
        Dim txtstate As TextBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("txtState")
        Dim txtzip As TextBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("txtZip")
        Dim txtcountry As TextBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("txtCountry")

        Dim txtext2 As TextBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("txtExt2")
        Dim txtext3 As TextBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("txtExt3")
        Dim txtext4 As TextBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("txtExt4")
        Dim txtext5 As TextBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("txtExt5")
        
        Dim strSelectCommand As String = "update trip4usdnn.Netism_MapExtreme_Locations set title = '" & txttitle.Text & "', description = '" & FreeTextBox1.Text & "', address = '" & txtaddress.Text & "', city = '" & txtcity.Text & "', state = '" & txtstate.Text & "', zip = '" & txtzip.Text & "', country = '" & txtcountry.Text & "', ext2 = '" & txtext2.Text & "', ext3 = '" & txtext3.Text & "', ext4 = '" & txtext4.Text & "', ext5 = '" & txtext5.Text & "'  where LocationID = " & lbl.Text & ""

        Dim dtVolumeOrder As New DataTable()
        Using sqlConn As New SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)
            Using adapPatientBills As New SqlDataAdapter(strSelectCommand, sqlConn)
                adapPatientBills.Fill(dtVolumeOrder)
            End Using
        End Using
        'iRowsCount = dtVolumeOrder.Rows.Count - 1
        'dsGridview.DataSource = dtVolumeOrder

        
        uxItemDetailGrid.EditIndex = -1
        dsGridview.DataBind()

        bind()

    End Sub

Open in new window

Commented:
you want something like this:
Dim chkIsActive As CheckBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("lblIsActive")

If chk.Checked Then
'IS CHECKED CODE HERE
End if

Open in new window

Commented:
sorry mistype:
Dim chkIsActive As CheckBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("lblIsActive")

If chkIsActive.Checked Then
'IS CHECKED CODE HERE
End if

Open in new window

Author

Commented:
what do I do here: 'IS CHECKED CODE HERE


Dim chkIsActive As CheckBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("lblIsActive")
       
         If chkIsActive.Checked Then
            ??? chkIsActive = true
         Else
            ??? chkIsActive = false
         End if

       
        Dim strSelectCommand As String = "update trip4usdnn.Netism_MapExtreme_Locations set title = '" & txttitle.Text & "', description = '" & FreeTextBox1.Text & "', address = '" & txtaddress.Text & "', city = '" & txtcity.Text & "', state = '" & txtstate.Text & "', zip = '" & txtzip.Text & "', country = '" & txtcountry.Text & "', ext2 = '" & txtext2.Text & "', ext3 = '" & txtext3.Text & "', ext4 = '" & txtext4.Text & "', ext5 = '" & txtext5.Text & "' IsActive = '" & ??????? & "' where LocationID = " & lbl.Text & ""

Commented:

If chkIsActive.Checked Then
            chkIsActive.Checked = true
         Else
            chkIsActive.Checked = false
         End if

Open in new window

Author

Commented:
I get an error on:  If chkIsActive.Checked Then
object not set to an instance of an object


 Dim chkIsActive As CheckBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("lblIsActive")
       
         If chkIsActive.Checked Then
         '      chkIsActive.Checked = true  ** commented this out in order to isolate the error
         Else
         '      chkIsActive.Checked = false ** ** commented this out in order to isolate the error

         End if

Commented:
Try this:

If chkIsActive.CheckState = 1 Then
   chkIsActive.Checked = true
 Else
   chkIsActive.Checked = false
End if

Open in new window

Commented:
if that does not work try this:

Dim chkIsActive As CheckBox = (CheckBox)uxItemDetailGrid.Rows(e.RowIndex).FindControl("lblIsActive")

Author

Commented:
Got it finnally, Thanks very much for your help
Commented:
No problem.

Author

Commented:
thanks again

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial