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. Working with a Gridview Edit Template at runtime.

Working with a Gridview Edit Template at runtime.

Scheduled Pinned Locked Moved ASP.NET
helpquestion
2 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.
  • D Offline
    D Offline
    dspyank
    wrote on last edited by
    #1

    Hi all, I have a gridview that has an edit template with a textbox and a dropdown list in it. At runtime the textbox and dropdown are invisible on the gridview (because they only show in edit view). When I click "Edit", the textbox and dropdown appear. I want to be able to reference the dropdown list but when I try to do so, I get the "Object reference not set to an instance of an object." error. Here is my code: protected void grdTrak_RowDataBound1(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ((DropDownList)e.Row.FindControl("dlStatus")).Attr ibutes.Add("onSelectedIndexChanged", "enableother(this)"); } } Does any one know what the problem could be? Thank you in advance! Dave

    K 1 Reply Last reply
    0
    • D dspyank

      Hi all, I have a gridview that has an edit template with a textbox and a dropdown list in it. At runtime the textbox and dropdown are invisible on the gridview (because they only show in edit view). When I click "Edit", the textbox and dropdown appear. I want to be able to reference the dropdown list but when I try to do so, I get the "Object reference not set to an instance of an object." error. Here is my code: protected void grdTrak_RowDataBound1(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ((DropDownList)e.Row.FindControl("dlStatus")).Attr ibutes.Add("onSelectedIndexChanged", "enableother(this)"); } } Does any one know what the problem could be? Thank you in advance! Dave

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      The row data bound happens for every row in the gridview. Only one row is set in edit mode, so you can not assume you will find the dropdown in each of the rows as they get data bound. Hope that helps. Ben

      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