DetailView issue setting checkbox

Posted on 2011-04-28
Last Modified: 2012-05-11
I have a grdiview and detailsview. When the user selects a specific record in the gridview the detailsview displays the detailed information of that specific record as we would expect.

All is working find except I cannot set the checkbox to either checked or not checked.

I am passing the information to a hidden field then deicding if the checkbox needs to be checked or not.It gets the error when it trys to set the checkbox.
I have check boxes in both the itemtemplate and edittemplate.

the error i get: Object reference not set to an instance of an object.

If someone could help me out that would be great.
<asp:TemplateField HeaderText="Filled" SortExpression="DateFilled" ItemStyle-HorizontalAlign="Center"
  <asp:HiddenField ID="hfFilled" runat="server" Value='<%# Bind("DateFilled") %>' />
 <asp:CheckBox ID="chkfilled" runat="server" Enabled="false" />
<asp:CheckBox ID="chkfilledEdit" runat="server"  />

Open in new window

Protected Sub dvFunctionVacancyDetails_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles dvFunctionVacancyDetails.DataBound
        If (dvFunctionVacancyDetails.CurrentMode = DetailsViewMode.ReadOnly) Then
            Dim hdfilled As HiddenField = CType(dvFunctionVacancyDetails.FindControl("hfFilled"), HiddenField)
            Dim filledEdit As CheckBox = CType(dvFunctionVacancyDetails.FindControl("rbFilledEdit"), CheckBox)
            If hdfilled Is Nothing OrElse hdfilled Is DBNull.Value Then
                filledEdit.Checked = False
                filledEdit.Checked = True
            End If

        End If
    End Sub

Open in new window

Question by:DStarkey
    LVL 9

    Expert Comment

    that means your checkbox cant be found
    LVL 9

    Accepted Solution

    try declaring the checkbox as:

    Dim filledEdit As CheckBox = DirectCast(DetailsView1.FindControl("filledEdit"), CheckBox)

    Author Comment

    I tried that but same result.... thanks for the suggestion I had my dba send me  a 0 or 1 for that field to tell me if it should be checked or not...


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
    Problem to be resolved in this article Currently, development of website and web application can be done without writing thousands of lines of programming code by hand. Description This can be done through by using a open source framework such …
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

    746 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

    19 Experts available now in Live!

    Get 1:1 Help Now