Checkbox not returning boolean values to DB

Last post 09-26-2006 8:56 AM by dtharby. 4 replies.

Sort Posts:

  • Checkbox not returning boolean values to DB

    09-25-2006, 3:58 PM
    • Member
      206 point Member
    • dtharby
    • Member since 06-16-2005, 5:40 AM
    • Posts 42

    Hi All,
    Having a problem getting boolean values from checkboxes on a formview grid.

    I am trying to allow the user to check which roles an album can be assigned to. In the database the IsPublic, IsFamily & IsFriends columns are BIT datatype.

    Checkboxes are coded as follows :-
     

    <asp:FormView ID="FormView1" Runat="server"
    	DataSourceID="ObjectDataSource1" DefaultMode="Insert"
    	BorderWidth="0" CellPadding="0">
    	<InsertItemTemplate>
    		<asp:RequiredFieldValidator	ID="RequiredFieldValidator1" Runat="server" ErrorMessage="You must choose a	title." ControlToValidate="TextBox1" Display="Dynamic" Enabled="false" />
    		<p>
    			Title<br />
    			<asp:TextBox ID="TextBox1" Runat="server" Width="200" Text='<%# Bind("Caption") %>' CssClass="textfield" />
    			<asp:CheckBox ID="CheckBox2" Runat="server" Checked='<%# Bind("IsPublic") %>' Text="Make this album Public" />
    			<br />
                            		<asp:CheckBox ID="CheckBox3" Runat="server" Checked='<%# Bind("IsFamily") %>' Text="Make this album Family" />
                            		<br />
                            		<asp:CheckBox ID="CheckBox4" Runat="server" Checked='<%# Bind("IsFriends") %>' Text="Make this album Friends" />
    		</p>
    		<p style="text-align:right;">
    			<asp:ImageButton ID="ImageButton1" Runat="server" CommandName="Insert" skinid="add"/>
    		</p>
    	</InsertItemTemplate>
    </asp:FormView>

    Problem is that when I just click on the Public checkbox, all the columns get '1' and on the others '0' gets entered.
    For this page, there is nothing in the code behind page.

    I added parameters for the InsertMethod for my datasource:-
     

    <asp:ObjectDataSource ID="ObjectDataSource1" Runat="server" TypeName="PhotoManager" 
         SelectMethod="GetAlbums" InsertMethod="AddAlbum" >
            <InsertParameters>
                <asp:Parameter Name="Caption" Type="String" />
                <asp:Parameter Name="IsPublic" Type="Boolean" />
                <asp:Parameter Name="IsFamily" Type="Boolean" />
                <asp:Parameter Name="IsFriends" Type="Boolean" />
            </InsertParameters>
    </asp:ObjectDataSource>
    Can anyone see where I am going wrong....

    Cheers
    Dan

  • Re: Checkbox not returning boolean values to DB

    09-25-2006, 10:37 PM
    • Star
      9,373 point Star
    • rexlin
    • Member since 07-17-2006, 8:43 AM
    • Posts 1,751

    Hi, Dan:

    What do you mean 'all the columns get '1' and on the others '0' gets entered'?



    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    This posting is provided "AS IS" with on warranties, and confers no rights.
  • Re: Checkbox not returning boolean values to DB

    09-26-2006, 3:16 AM
    • Member
      206 point Member
    • dtharby
    • Member since 06-16-2005, 5:40 AM
    • Posts 42

    Ok.. if I check the Public checkbox (checkbox3) and click my add imagebutton, then in the associated table the columns IsPublic, Is Family & IsFriends all have a '1' entered in the row for the new album.

    However if I check either of the other 2 checkboxes, then '0' gets added to the columns for the new entry.

     Example:-

    AlbumID 7 was added checking the Friends checkbox, in this case I would have expected the row to read 0,1,0
    AlbumID 8 was added checking the Public checkbox, in this case I would have expected the row to read 1,0,0

     

  • Re: Checkbox not returning boolean values to DB

    09-26-2006, 3:40 AM
    • Star
      9,373 point Star
    • rexlin
    • Member since 07-17-2006, 8:43 AM
    • Posts 1,751

    Hi,Dan:

    The code above seems ok.

    Maybe you can show the insert statement and try to have a breakpoint before the insert statement to check what is the input for the three parameters.



    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    This posting is provided "AS IS" with on warranties, and confers no rights.
  • Re: Checkbox not returning boolean values to DB

    09-26-2006, 8:56 AM
    Answer
    • Member
      206 point Member
    • dtharby
    • Member since 06-16-2005, 5:40 AM
    • Posts 42

    Thanks for the reply Rex.

    I found the problem and it was that I had not changed the parameters in the AddAlbum sub to accommodate the IsFamily and IsFriends values

    One of the pitfalls of copy and paste !!!

    Now when I add the album, the table columns are completed correctly.

    Thanks again for your help and fresh pair or eyes !!!!

    Big Smile

Page 1 of 1 (5 items)