Solved

DBNull, checkbox update issue in formview control asp.net 2.0

Posted on 2006-11-27
2
905 Views
Last Modified: 2012-05-05
Hi All,

I had an issue using a checkbox where my sql server database uses the bit data type but allows NULL values.  it would give me an error message.  I worked around the issue with the following formula and functions...

getChkStat( Eval("ApplicantHas3YrsExperience").ToString())

getChkStat calls the functions below in the code behind...


Public Shared Function IsNullStr(ByVal s As String) As Boolean
        If s = "1" OrElse s.ToUpper = "TRUE" Then
            Return False
        End If
        Return True
    End Function

    Public Function getChkStat(ByVal s As String) As Boolean

        If IsNullStr(s) Then
            Return False
        Else
            If s = "True" Then
                Return True
            Else
                Return False
            End If
        End If
    End Function



If I use Bind("ApplicantHas3YrsExperience") instead I get an error due to the null value.  The problem with
getChkStat( Eval("ApplicantHas3YrsExperience").ToString())  is that I cannot get the formview to update after I check the checkbox.  I put a a check in, hit Update and then there is no check - not good!  Every other textbox that I change does get updated just not my checkbox.  There must be a better way to do this.  Thanks!
0
Comment
Question by:kenadelglass
2 Comments
 
LVL 1

Author Comment

by:kenadelglass
ID: 18028985
Well I spent a good portion of the morning and answered my own question.  This is the second question in a row.  Where have all the experts gone?

My solution was to get the checkbox value in the page load and then did a Replace to change the parameter to a 1 or a 0...  This worked.  If nobody has a better way then I am going to ask for my points returned.  The code is below...

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Page.IsPostBack Then
            Dim cb As CheckBox

            cb = FormView1.FindControl("ApplicantHas3YrsExperienceCheckBox")
            If cb.Checked Then

                SqlDataOrigHist.UpdateCommand = SqlDataOrigHist.UpdateCommand.Replace("@ApplicantHas3YrsExperience", "1")
            Else
                SqlDataOrigHist.UpdateCommand = SqlDataOrigHist.UpdateCommand.Replace("@ApplicantHas3YrsExperience", "0")
            End If

        End If
    End Sub

0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 18036268
Closed, 500 points refunded.
PashaMod
Community Support Moderator
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now