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. How to pass values between FormViews ?

How to pass values between FormViews ?

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
2 Posts 1 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.
  • F Offline
    F Offline
    FionaDM
    wrote on last edited by
    #1

    I want to pass a value from one formview to a second, FormView1 to FormView2. I start with FormView1 and insert a record. The fields are FormView1_ID, FormView1_Name, ... Following insertion in FormView1 I want to display a second FormView called FormView2 which is also in insertmode. The fields in FormView2 are FormView2_ID, FormView1_ID, FormView2_whatever etc. I want to insert a new record in FormView2 where FormView1_ID is the ID of the just inserted FormView1 record. I have had a fairly intensive trawl through the MSDN walkthroughs, how tos etc but could not find anything I could apply to my situation. If there's something out there please point me at it. Anyway, I decided to try to pass the ID from the first to the second FormView using OnInserting method for FormView2 and by determining the value of FormView1_ID using FindControl. But I'm getting an error! The common one 'Object reference not set to an instance of an object.'. Here's my method in its entirety. protected void FormView2_Sqldatasource2_Inserting(Object sender, SqlDataSourceCommandEventArgs e) { TextBox NewID = null; NewID = (TextBox)FormView1.FindControl("FormView1_ID"); SqlDataSource2.InsertParameters["FormView1_ID"].DefaultValue = NewID.Text; } This error occurs at the line SqlDataSource2.InsertParameters["FormView1_ID"].DefaultValue = NewID.Text; Thanks Maj

    F 1 Reply Last reply
    0
    • F FionaDM

      I want to pass a value from one formview to a second, FormView1 to FormView2. I start with FormView1 and insert a record. The fields are FormView1_ID, FormView1_Name, ... Following insertion in FormView1 I want to display a second FormView called FormView2 which is also in insertmode. The fields in FormView2 are FormView2_ID, FormView1_ID, FormView2_whatever etc. I want to insert a new record in FormView2 where FormView1_ID is the ID of the just inserted FormView1 record. I have had a fairly intensive trawl through the MSDN walkthroughs, how tos etc but could not find anything I could apply to my situation. If there's something out there please point me at it. Anyway, I decided to try to pass the ID from the first to the second FormView using OnInserting method for FormView2 and by determining the value of FormView1_ID using FindControl. But I'm getting an error! The common one 'Object reference not set to an instance of an object.'. Here's my method in its entirety. protected void FormView2_Sqldatasource2_Inserting(Object sender, SqlDataSourceCommandEventArgs e) { TextBox NewID = null; NewID = (TextBox)FormView1.FindControl("FormView1_ID"); SqlDataSource2.InsertParameters["FormView1_ID"].DefaultValue = NewID.Text; } This error occurs at the line SqlDataSource2.InsertParameters["FormView1_ID"].DefaultValue = NewID.Text; Thanks Maj

      F Offline
      F Offline
      FionaDM
      wrote on last edited by
      #2

      Got it. I was casting incorrectly. Method should look like: protected void FormView2_Sqldatasource2_Inserting(Object sender, SqlDataSourceCommandEventArgs e) { Label NewID = null; NewID = (Label)FormView1.FindControl("FormView1_ID"); SqlDataSource2.InsertParameters["FormView1_ID"].DefaultValue = NewID.Text; }

      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