westdh
asked on
asp.net: how to update a checkbox in an editItemTemplate true or false
how to update a checkbox in an editItemTemplate - true or false
<asp:TemplateField ItemStyle-Width="220" ItemStyle-BackColor = "#F4F4F4" ItemStyle-HorizontalAlign= "Center" HeaderStyle-BackColor="#A1 C1D9" 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>
<asp:TemplateField ItemStyle-Width="220" ItemStyle-BackColor = "#F4F4F4" ItemStyle-HorizontalAlign=
<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>
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.
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.
ASKER
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.
ASKER
Here is my update proc.
I can add this: ???
Dim chkIsActive As CheckBox = uxItemDetailGrid.Rows(e.Ro wIndex).Fi ndControl( "chkIsActi ve")
what else:
what do I add in the sql update
I can add this: ???
Dim chkIsActive As CheckBox = uxItemDetailGrid.Rows(e.Ro
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
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
sorry mistype:
Dim chkIsActive As CheckBox = uxItemDetailGrid.Rows(e.RowIndex).FindControl("lblIsActive")
If chkIsActive.Checked Then
'IS CHECKED CODE HERE
End if
ASKER
what do I do here: 'IS CHECKED CODE HERE
Dim chkIsActive As CheckBox = uxItemDetailGrid.Rows(e.Ro wIndex).Fi ndControl( "lblIsActi ve")
If chkIsActive.Checked Then
??? chkIsActive = true
Else
??? chkIsActive = false
End if
Dim strSelectCommand As String = "update trip4usdnn.Netism_MapExtre me_Locatio ns 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 & ""
Dim chkIsActive As CheckBox = uxItemDetailGrid.Rows(e.Ro
If chkIsActive.Checked Then
??? chkIsActive = true
Else
??? chkIsActive = false
End if
Dim strSelectCommand As String = "update trip4usdnn.Netism_MapExtre
If chkIsActive.Checked Then
chkIsActive.Checked = true
Else
chkIsActive.Checked = false
End if
ASKER
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.Ro wIndex).Fi ndControl( "lblIsActi ve")
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
object not set to an instance of an object
Dim chkIsActive As CheckBox = uxItemDetailGrid.Rows(e.Ro
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
Try this:
If chkIsActive.CheckState = 1 Then
chkIsActive.Checked = true
Else
chkIsActive.Checked = false
End if
if that does not work try this:
Dim chkIsActive As CheckBox = (CheckBox)uxItemDetailGrid .Rows(e.Ro wIndex).Fi ndControl( "lblIsActi ve")
Dim chkIsActive As CheckBox = (CheckBox)uxItemDetailGrid
ASKER
Got it finnally, Thanks very much for your help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks again
ASKER