VS 2012 Get Checkbox Checked Value in DetailsView-VBForums
Results 1 to 2 of 2

Thread: Get Checkbox Checked Value in DetailsView

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2015
    Posts
    18

    Get Checkbox Checked Value in DetailsView

    I have created a single checkbox in the DetailsView of my Asp page. I then created VB code behind to set the value =1 if the checkbox is checked and value =0 if checkbox is not checked. I cannot get the code to work. The record will get created in my SQL database, but the checkbox field remains NULL

    In SQL table, my field and datatype is: Greenfield, bit, NULL

    The beginning code for DetailsView1 is:
    Code:
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" BackColor="White" BorderColor="White" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" DataKeyNames="ID" DataSourceID="tblEntryFormDS" style="text-align: left; margin-bottom: 0px;" Font-Bold="False" Font-Names="Arial" Font-Size="Small" DefaultMode="Insert" GridLines="Horizontal" CssClass="auto-style47">
    <AlternatingRowStyle BorderStyle="None" />
    The code for the checkbox within DetailsView1:
    Code:
    <asp:CheckBox ID="CheckBox1" runat="server"  Text="    Greenfield" AutoPostBack="True" />
    And the VB code behind. I originally used OnCheckedChanged but that wasnt working and it was suggested of me to use DetailsView1_ItemInserting instead: (The Dropdownlists in the code are working)
    Code:
        Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles DetailsView1.ItemInserting
            Dim DropDownList6 As DropDownList = CType(DetailsView1.FindControl("DropDownList6"), DropDownList)
            Dim DropDownlist9 As DropDownList = CType(DetailsView1.FindControl("DropDownList9"), DropDownList)
            Dim CheckBox1 As CheckBox = DirectCast(DetailsView1.FindControl("CheckBox1"), CheckBox)
            Dim strOutput As String = String.Empty
            If CheckBox1.Checked = True Then
                strOutput += 1
            Else
                strOutput = 0
            End If
            e.Values("DP_Facility") = DropDownList6.SelectedValue
            e.Values("Facility") = DropDownlist9.SelectedValue
            e.Values("Greenfield") = strOutput
        End Sub

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,474

    Re: Get Checkbox Checked Value in DetailsView

    That's not a VB.Net question.
    Try the ASP.Net forum
    I've notified a moderator who will move your thread.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.