Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 105107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:23:13+00:00 2026-05-11T01:23:13+00:00

I’m getting the error Object reference not set to an instance of an object.

  • 0

I’m getting the error ‘Object reference not set to an instance of an object.’ when trying to reference a HiddenField (lvEditProjectSteps_hdnStepStatusId for future reference) from the EditItem during the OnItemUpdating event after the Update event fires in a ListView. This only occurs on the FIRST item in the ListView. I checked the source and the HTML is being rendered properly.

ANY insight is appreciated! Thanks in advance…

Source error:

var lvEditProjectSteps_hdnStepStatusId = (HiddenField) lvEditProjectSteps.EditItem.FindControl('lvEditProjectSteps_hdnStepStatusId'); 

Here’s the aspx side of the ListView:

<asp:ListView ID='lvEditProjectSteps' runat='server'   OnItemDataBound='lvEditProjectSteps_OnItemDataBound'    OnItemUpdating='lvEditProjectSteps_OnItemUpdating'    DataSourceID='odsEditProjectStep'    DataKeyNames='Id'>   <LayoutTemplate>     <table class='standard-box-style' style='width:800px'>       <thead>         <tr>           <th>&nbsp;</th>           <th>&nbsp;</th>           <th>Created</th>           <th>Updated</th>         </tr>       </thead>       <tbody>         <asp:PlaceHolder ID='itemPlaceHolder' runat='server' />       </tbody>     </table>   </LayoutTemplate>   <ItemTemplate>     <tr>       <td style='width:50px'<%# (Container.DisplayIndex % 2 == 0)?'':' class=\'row-alternating\'' %>>         <asp:ImageButton ID='lvEditProjectSteps_btnEdit' runat='server'            ImageUrl='~/admin/images/icons/edit.gif'            AlternateText='Edit'            SkinID='interfaceButton'           CommandName='Edit' />         <asp:HiddenField ID='lvEditProjectSteps_hdnId' runat='server' Value='<%# Bind('Id')%>' />         <asp:HiddenField ID='lvEditProjectSteps_hdnStepStatusId' runat='server' Value='<%# Bind('StepStatusId')%>' />         <asp:HiddenField ID='lvEditProjectSteps_hdnStepStatusStepId' runat='server' Value='<%# Bind('StepStatus_StepId')%>' />       </td>       <td style='width:30px'<%# (Container.DisplayIndex % 2 == 0)?'':' class=\'row-alternating\'' %>><asp:Image ID='imgStatus' runat='server' /></td>       <td style='width:75px'<%# (Container.DisplayIndex % 2 == 0)?'':' class=\'row-alternating\'' %>><asp:Literal ID='litTsCreated' runat='server' /></td>       <td style='width:75px'<%# (Container.DisplayIndex % 2 == 0)?'':' class=\'row-alternating\'' %>><asp:Literal ID='litTsUpdated' runat='server' /></td>     </tr>   </ItemTemplate>   <EditItemTemplate>     <tr>       <td style='width:50px'<%# (Container.DisplayIndex % 2 == 0)?'':' class=\'row-alternating\'' %>>         <asp:ImageButton ID='lvEditProjectSteps_btnUpdate' runat='server'            ImageUrl='~/admin/images/icons/save.png'            AlternateText='Save'            SkinID='interfaceButton'           CommandName='Update'            ValidationGroup='EditProjectStepsSave' />         <asp:ImageButton ID='lvEditProjectSteps_btnCancel' runat='server'            ImageUrl='~/admin/images/icons/cancel.png'            AlternateText='Cancel'            SkinID='interfaceButton'           CommandName='Cancel' />         <asp:HiddenField ID='lvEditProjectSteps_hdnId' runat='server' Value='<%# Bind('Id')%>' />         <asp:HiddenField ID='lvEditProjectSteps_hdnStepStatusId' runat='server' Value='<%# Bind('StepStatusId')%>' />         <asp:HiddenField ID='lvEditProjectSteps_hdnStepStatusStepId' runat='server' Value='<%# Bind('StepStatus_StepId')%>' />       </td>       <td style='width:180px' colspan='3'<%# (Container.DisplayIndex % 2 == 0)?'':' class=\'row-alternating\'' %>>         <div><strong>Status</strong></div>         <div class='radiobuttonlist-status'>           <asp:RadioButtonList ID='lvEditProjectSteps_rblStatus' runat='server'                  RepeatDirection='Horizontal'                 AutoPostBack='true'             OnSelectedIndexChanged='lvEditProjectSteps_rblStatus_OnSelectedIndexChanged'>             <asp:ListItem Value='1'><img src='/images/icon/project-status/1.png' alt='Error' /></asp:ListItem>             <asp:ListItem Value='2'><img src='/images/icon/project-status/2.png' alt='In Progress' /></asp:ListItem>             <asp:ListItem Value='3'><img src='/images/icon/project-status/3.png' alt='Complete' /></asp:ListItem>           </asp:RadioButtonList>           <asp:RequiredFieldValidator ID='valRequired_lvEditProjectSteps_rblStatus' runat='server'              ControlToValidate='lvEditProjectSteps_rblStatus'              SetFocusOnError='true'             Display='Dynamic'              ErrorMessage='<br />^ required ^'              ValidationGroup='EditProjectStepsSave' />         </div>       </td>     </tr>   </EditItemTemplate> </asp:ListView> 

And the code-behind:

protected void lvEditProjectSteps_OnItemDataBound(object sender, ListViewItemEventArgs e) {   if (e.Item.ItemType == ListViewItemType.DataItem)   {     var info = (ProjectStepInfo)DataBinder.GetDataItem(e.Item);      // View Item     var litTsCreated = (Literal)e.Item.FindControl('litTsCreated');     var litTsUpdated = (Literal)e.Item.FindControl('litTsUpdated');     var imgStatus = (Image) e.Item.FindControl('imgStatus');      if (litTsCreated != null) litTsCreated.Text = String.Format('{0:d}', info.TsCreated);     if (litTsUpdated != null) litTsUpdated.Text = String.Format('{0:d}', info.TsCreated);     if (imgStatus != null) imgStatus.ImageUrl = String.Format('/images/icon/project-status/{0}.png', info.StepStatus_StatusId);      // Edit Item     var lvEditProjectSteps_rblStatus = (RadioButtonList) e.Item.FindControl('lvEditProjectSteps_rblStatus');     if (lvEditProjectSteps_rblStatus != null) lvEditProjectSteps_rblStatus.SelectedValue = info.StepStatus_StatusId.ToString();   } } protected void lvEditProjectSteps_OnItemUpdating(object sender, ListViewUpdateEventArgs e) {   if (IsValid)   {     var oController = new Controller();     var lvEditProjectSteps_hdnStepStatusId = (HiddenField) lvEditProjectSteps.EditItem.FindControl('lvEditProjectSteps_hdnStepStatusId');     var lvEditProjectSteps_hdnStepStatusStepId = (HiddenField) lvEditProjectSteps.EditItem.FindControl('lvEditProjectSteps_hdnStepStatusStepId');     var lvEditProjectSteps_rblStatus = (RadioButtonList) lvEditProjectSteps.EditItem.FindControl('lvEditProjectSteps_rblStatus');     var infoStepStatus = oController.StepStatus_SelectOne_StepId_StatusId(Convert.ToInt32(lvEditProjectSteps_hdnStepStatusStepId.Value), Convert.ToInt32(lvEditProjectSteps_rblStatus.SelectedValue));     if (lvEditProjectSteps_hdnStepStatusId != null)     {       e.NewValues['ProjectId'] = Convert.ToInt32(lvEditProjectSteps_hdnProjectId.Value);       e.NewValues['StepStatusId'] = infoStepStatus.Id;     }     else     {       Response.Write('cancel');       e.Cancel = true;     }   }   else   {     Response.Write('cancel, not valid');     e.Cancel = true;   } } protected void lvEditProjectSteps_rblStatus_OnSelectedIndexChanged(object sender, EventArgs e) {   var oController = new Controller();   var rbl = (RadioButtonList)sender;   var lvEditProjectSteps_txtText = (TextBox) rbl.NamingContainer.FindControl('lvEditProjectSteps_txtText');   var lvEditProjectSteps_txtComment = (TextBox)rbl.NamingContainer.FindControl('lvEditProjectSteps_txtComment');   var lvEditProjectSteps_hdnStepStatusStepId = (HiddenField) rbl.NamingContainer.FindControl('lvEditProjectSteps_hdnStepStatusStepId');   if (!String.IsNullOrEmpty(lvEditProjectSteps_hdnStepStatusStepId.Value) && lvEditProjectSteps_txtText != null && lvEditProjectSteps_txtComment != null)   {     var infoStep = oController.Step_SelectOne(Convert.ToInt32(lvEditProjectSteps_hdnStepStatusStepId.Value));     var infoStepStatus = oController.StepStatus_SelectOne_StepId_StatusId(Convert.ToInt32(lvEditProjectSteps_hdnStepStatusStepId.Value), Convert.ToInt32(rbl.SelectedValue));      lvEditProjectSteps_txtText.Text = infoStep.Name;     lvEditProjectSteps_txtComment.Text = infoStepStatus.Text;   } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:23:14+00:00Added an answer on May 11, 2026 at 1:23 am

    I solved my own problem. There seems to be a bug when selecting a the edit ListViewItem like this (using the example above):

    lvEditProjectSteps.EditItem 

    but not when you use this method:

    lvEditProjectSteps.Items[lvEditProjectSteps.EditIndex] 

    hope this helps someone else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 57k
  • Answers 57k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The last two are identical; 'atomic' is the default behavior… May 11, 2026 at 8:28 am
  • added an answer Not as simply as you'd like, I'm sorry. One way… May 11, 2026 at 8:28 am
  • added an answer I did: sudo gem install mechanize and the following seems… May 11, 2026 at 8:28 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Related Questions

Loading...

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.