DetailsView EditItemTemplate CheckBox control

Last post 03-17-2006 5:09 PM by linkyossy. 6 replies.

Sort Posts:

  • DetailsView EditItemTemplate CheckBox control

    03-17-2006, 1:31 PM
    • Member
      485 point Member
    • linkyossy
    • Member since 02-09-2006, 1:52 AM
    • Posts 98

    How do I reference checkbox1 or checkbox2 that is in the EditItemTemplate at Serverside. It is gives error when I try to declare Checkbox1 or checkbox2. Error: CheckBox1 is not declared. When I checked the ID property of checkbox1 this is what I see DetailsView1.Field3SpecializationData.EditItemTemplate.Checkbox1 and I tried to use that but gave error too. Please Help. Thanks.

    If checkbox1.checked = true then
    'perform operation
    Else
    'message
    End If

    It gives error usingthe above code. What do I do. Below is my detailsView control that contains the checkbox.

    <asp:DetailsView ID = DetailsView1 runat ="server" AutoGenerateRows="False" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="Student_ID" DataSourceID="SqlDataSource1"> <Fields> <asp:BoundField DataField="Student_ID" HeaderText="Student ID" ReadOnly="True" SortExpression="Student_ID" />
    <asp:BoundField DataField="Student_Name" SortExpression="Student_Name" /><asp:BoundField DataField="Date" SortExpression="Date" />
    <asp:TemplateField <EditItemTemplate><asp:CheckBox ID="Checkbox1" runat="server" Checked='<%# Bind("Specialization_Data") %>'> Enabled="false" />
    </EditItemTemplate>
    <EditItemTemplate>
    <asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("Specialization_General") %>'Enabled="false" /> </EditItemTemplate></asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MSIS_POSConnectionString %>"
    ProviderName="<%$ ConnectionStrings:MSIS_POSConnectionString.ProviderName %>"
    SelectCommand="SELECT * FROM [StudentInformation] WHERE ([Student_ID] = ?)" UpdateCommand="UPDATE [StudentInformation] SET [Student_Name] = ?, [Specialization_Data] = ?, [Specialization_General] = ?, WHERE [Student_ID] = ?">

    Thanks

     

     

  • Re: DetailsView EditItemTemplate CheckBox control

    03-17-2006, 2:53 PM
    • All-Star
      32,472 point All-Star
    • augustwind
    • Member since 07-21-2002, 11:16 PM
    • Garland, TX
    • Posts 4,546
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    You can't use checkbox1 (or 2) directly, you must use the FindControl method - to find it inside the DetailsView.

    the following code is adapted from a sample on ASPNet101.com dealing with a GridView - it might not be exactly correct, but it's the general form of what you need - I just don't have time right at this moment to test it.

           Dim dgItem As DetailsViewRow
            Dim chkGView As System.Web.UI.WebControls.CheckBox
                For Each dgItem In DetailsView1 .Rows
                    chkGView = dgItem.FindControl("checkbox1")
                    if chkGView.Checked=true then
                      ' whatever
                   else
                      ' whatever else
                   end if
                Next

    David Wier
    MCP/ASPInsider
    ASPNet101.com - where to look first!
    Replace It! - the newest from August Wind - search/replace in multiple files
    Control Grouper - easily control properties for multiple controls with one control!
    Calendar Express - The Best HTML Calendar Generator on the web!
    (Please 'Mark as Answer' when it applies)
  • Re: DetailsView EditItemTemplate CheckBox control

    03-17-2006, 3:22 PM
    • Member
      485 point Member
    • linkyossy
    • Member since 02-09-2006, 1:52 AM
    • Posts 98

    Thanks Augustwind, I tried the code the following way but it didn't respond. Onclick the Edit Link, there are two link that appear, the Cancel and Update link. Although the code didn't respond but I will like it to when the update Link is clicked. Please Help. Note: It didn't respond at all to either way. Thanks.

    Sub DetailsView1_RowUpdate(ByVal sender As Object, ByVal e As DetailsViewUpdateEventArgs)
    Dim dgItem As DetailsViewRow
    Dim chkGView As System.Web.UI.WebControls.CheckBox
    For Each dgItem In DetailsView1.Rows
    chkGView = dgItem.FindControl(
    "checkbox1")
    If chkGView.Checked = True Then
    ' whatever
    lblNext.Text = "Selected"
    Else
    ' whatever else
    End If
    Next
    End Sub

  • Re: DetailsView EditItemTemplate CheckBox control

    03-17-2006, 3:36 PM
    • All-Star
      32,472 point All-Star
    • augustwind
    • Member since 07-21-2002, 11:16 PM
    • Garland, TX
    • Posts 4,546
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs
    I'm a little unclear about the timing for which you want this Checkbox checking to occur - do you want it to happen as it's being updated, or after it's been updated?
    David Wier
    MCP/ASPInsider
    ASPNet101.com - where to look first!
    Replace It! - the newest from August Wind - search/replace in multiple files
    Control Grouper - easily control properties for multiple controls with one control!
    Calendar Express - The Best HTML Calendar Generator on the web!
    (Please 'Mark as Answer' when it applies)
  • Re: DetailsView EditItemTemplate CheckBox control

    03-17-2006, 3:50 PM
    • Member
      485 point Member
    • linkyossy
    • Member since 02-09-2006, 1:52 AM
    • Posts 98
    Thanks Augustwind, I will like the Checkbox checking to respond upon clicking the Update Button. That is the 'Message should comeup when user click the update button. Thanks.
  • Re: DetailsView EditItemTemplate CheckBox control

    03-17-2006, 4:17 PM
    • All-Star
      32,472 point All-Star
    • augustwind
    • Member since 07-21-2002, 11:16 PM
    • Garland, TX
    • Posts 4,546
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    Actually, when the user clicks the Update button, there are 2 possible events :
    onItemUpdating, before the actual update) and
    onItemUpdated - after the update - -

    so - I'll assume you mean after the update occurs.

    Try changing the signature of your subroutine to use 'DetailsViewUpdatedEventArgs'

    also - double check, in the DetailsView tag, that 'DetailsView1_RowUpdate' is referenced like:

    OnItemUpdated="DetailsView1_RowUpdate"

    David Wier
    MCP/ASPInsider
    ASPNet101.com - where to look first!
    Replace It! - the newest from August Wind - search/replace in multiple files
    Control Grouper - easily control properties for multiple controls with one control!
    Calendar Express - The Best HTML Calendar Generator on the web!
    (Please 'Mark as Answer' when it applies)
  • Re: DetailsView EditItemTemplate CheckBox control

    03-17-2006, 5:09 PM
    • Member
      485 point Member
    • linkyossy
    • Member since 02-09-2006, 1:52 AM
    • Posts 98
    Augustwind, I have tried that and am still getting no response oncheck of the checkbox. Please What else can I do or what am I doing wrong. Thanks
Page 1 of 1 (7 items)