Solved

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

Posted on 2006-11-27
2
948 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…

752 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