In Visual Web Developer Ihave created a data input form based on the documentation I found in the .NETFramework Class Library (SqlDataSource.InsertCommand Property). Originally my form contained 4 textboxes(FirstName, LastName, Phone, Email) and worked fine. All this data is nvarchar string data.
When I added a checkbox Iget an error that"Stringwas not recognized as a valid Boolean" when the checkbox is checked. When the checkbox is unchecked the data is input without a problem. This is a bit data field in the table.
Here is my VB code, InsertParameters for my SqlDataSource1, and button code:
<scriptrunat="server">
PrivateSub InsertData(ByValSourceAsObject,ByVal eAsEventArgs)
SqlDataSource1.Insert()
EndSub
</script>
<InsertParameters>
<asp:formParameterName="FirstName"Type="String"FormField="txtFirstName"/>
<asp:formParameterName="LastName"Type="String"FormField="txtLastName"/>
<asp:formParameterName="Phone"Type="String"FormField="txtPhone"/>
<asp:formParameterName="Email"Type="String"FormField="txtEmail"/>
<asp:formParameterName="FreeInfo"Type="Boolean"FormField="checkbox1"/>
</InsertParameters>
<asp:Buttonid="Button1"runat="server"text="Submit"OnClick="insertdata"/>
I suspect that the problemis with the VB code which will only accept string input data, but don't knowhow to fix it. Any thoughts on how tofix this problem? Thanks in advance forany help provided.
Check box return "On" whener page is postback
It does'nt return checked or unchecked.
You have to check this checkBox by code before inserting the data.
If checkBox is checked set the parametervalue = 1 else 0 .
Thank
Kunal
|||
Thanks for your feedback. I tried to implement your suggestions, but get this error message:
String was not recognized as a valid Boolean.
Here is my new VB code:
Private Sub InsertName(ByVal Source As Object, ByVal e As EventArgs)
If (CheckBox1.Checked = True) Then
CheckBox1.Equals(1)
Else : CheckBox1.Equals(0)
End If
SqlDataSource1.Insert()
End Sub
I am a newbie to VB, so my codeprobably doesn't accurately implement your recommendations. Any helpyou can provide in getting this to work will be greatly appreciated.
|||
Hi,
The formParameter always gets value from the Text property of the controls. In this case, you can try to use ControlParameter instead.
<asp:controlParameter Name="FreeInfo" ControlId="checkbox1" PropertyName="Checked"/>
HTH. If this does not answer your question, please feel free to mark the post as Not Answered and reply. Thank you!
||| Thanks Kevin. That's exactly what I needed.
No comments:
Post a Comment