?
Solved

DetailView issue setting checkbox

Posted on 2011-04-28
3
Medium Priority
?
263 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

0
Comment
Question by:DStarkey
  • 2
3 Comments
 
LVL 9

Expert Comment

by:TonyReba
ID: 35487905
that means your checkbox cant be found
0
 
LVL 9

Accepted Solution

by:
TonyReba earned 2000 total points
ID: 35487917
try declaring the checkbox as:

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

Author Comment

by:DStarkey
ID: 35490603
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...

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
No other job is as rewarding and demanding as building an iPhone app is. It is not really in the hands of the developer for the success of an iPhone app. Many factors operate jointly for every iOS application's success in the market.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

571 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