Solved

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

Posted on 2006-11-27
2
941 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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

827 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