Solved

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

Posted on 2006-11-27
2
927 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error in query expression 3 42
Entity Framework 7 41
What namespace do I need to import? 2 25
VB.net Move a class from Solution Items to a project 2 22
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

815 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

9 Experts available now in Live!

Get 1:1 Help Now