We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

DetailView issue setting checkbox

Medium Priority
308 Views
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"
  HeaderStyle-HorizontalAlign="Right">
 <ItemTemplate>
  <asp:HiddenField ID="hfFilled" runat="server" Value='<%# Bind("DateFilled") %>' />
 <asp:CheckBox ID="chkfilled" runat="server" Enabled="false" />
 </ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="chkfilledEdit" runat="server"  />
  </EditItemTemplate>
  </asp:TemplateField>

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
            Else
                filledEdit.Checked = True
            End If

        End If
    End Sub

Open in new window

Comment
Watch Question

Commented:
that means your checkbox cant be found
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
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...

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.