Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem while binding data to a DropDownList in GridView's EditItemTemplate column

Problem while binding data to a DropDownList in GridView's EditItemTemplate column

Scheduled Pinned Locked Moved ASP.NET
helpcsharpwpfwcflearning
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    YazhiniP
    wrote on last edited by
    #1

    Hi, I am a beginner in .NET. I Placed a DropDownList in GridView's EditItemTemplate field. Whenever i click the Edit Button i am getting a runtime error stating "object Reference not set to an instance of the object". That is,when i try to find the DropDownList using FindControl method,it is always null. I have tried a lot of code in both GridView's RowBound and RowEditing events. But,all the time i am getting the same error. Below i have given the code that i tried in RowEditing event. It will be very helpful if anyone help me in resolving this error. .aspx source code /> .cs file protected void gvDocumentDetails_RowEditing(object sender, GridViewEditEventArgs e) { int intEditIndex; intEditIndex = e.NewEditIndex; gvDocumentDetails.EditIndex = e.NewEditIndex; PopulateApprovalStatus(intEditIndex); } protected void PopulateApprovalStatus(int intRowIndex) { DataSet dsApprovalStatus = new DataSet(); DropDownList ddlApprovalStatus = null; ObjReviewDocumentsBL.LoadApprovalStatus(out dsApprovalStatus); ddlApprovalStatus = (DropDownList)gvDocumentDetails.Rows[intRowIndex].Cells[6].FindControl("ddlApprovalStatus"); ddlApprovalStatus.DataSource = dsApprovalStatus;

    S 1 Reply Last reply
    0
    • Y YazhiniP

      Hi, I am a beginner in .NET. I Placed a DropDownList in GridView's EditItemTemplate field. Whenever i click the Edit Button i am getting a runtime error stating "object Reference not set to an instance of the object". That is,when i try to find the DropDownList using FindControl method,it is always null. I have tried a lot of code in both GridView's RowBound and RowEditing events. But,all the time i am getting the same error. Below i have given the code that i tried in RowEditing event. It will be very helpful if anyone help me in resolving this error. .aspx source code /> .cs file protected void gvDocumentDetails_RowEditing(object sender, GridViewEditEventArgs e) { int intEditIndex; intEditIndex = e.NewEditIndex; gvDocumentDetails.EditIndex = e.NewEditIndex; PopulateApprovalStatus(intEditIndex); } protected void PopulateApprovalStatus(int intRowIndex) { DataSet dsApprovalStatus = new DataSet(); DropDownList ddlApprovalStatus = null; ObjReviewDocumentsBL.LoadApprovalStatus(out dsApprovalStatus); ddlApprovalStatus = (DropDownList)gvDocumentDetails.Rows[intRowIndex].Cells[6].FindControl("ddlApprovalStatus"); ddlApprovalStatus.DataSource = dsApprovalStatus;

      S Offline
      S Offline
      Samer Aburabie
      wrote on last edited by
      #2

      Hi there, I think you already knew half the solution to your problem ... the returned null object from FindControl is because he really cant find it in Cell[6]... well try going more deeper ... use the debugger to see all controls inside Cell[6] and then in each one try finding your dropdownlist ... I think all you have to do is go one step deeper as I recall for the EditTemplate.

      Sincerely Samer Abu Rabie Imagination is more important than knowledge !

      Y 1 Reply Last reply
      0
      • S Samer Aburabie

        Hi there, I think you already knew half the solution to your problem ... the returned null object from FindControl is because he really cant find it in Cell[6]... well try going more deeper ... use the debugger to see all controls inside Cell[6] and then in each one try finding your dropdownlist ... I think all you have to do is go one step deeper as I recall for the EditTemplate.

        Sincerely Samer Abu Rabie Imagination is more important than knowledge !

        Y Offline
        Y Offline
        YazhiniP
        wrote on last edited by
        #3

        Yes...i might have been given as Cell[5].But,that alone is not the mistake. I have resolved the problem now... I think the main mistake is that i haven't filled the Grid at the RowEditing event. After doing that,i got it. Anyhow,thanks for helping me... Now,i have another doubt. How to retrive the cell value of the BoundField in the RowUpdating event?. For example,i have to retrive the IncidentNo whose ApprovalStatus has been edited and have to pass both the ApprovalStatus and IncidentNo values to another function. Since The IncidentNo column is a BoundField control,how to get it's value in the RowUpdating event?

        Yazhini

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups