Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-11-27
2
Medium Priority
?
953 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

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

824 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