Display Insert Template on FormView when "Add New" button is clicked



I'm fairly new to working with ASP web controls, and am running into
what seems to be a ridiculous problem that I'm hoping will be a breeze
for an experienced ASP developer.

I have a GridView and a FormView on the same page, where the GridView
is visible at page load, and the FormView is set to Edit mode by
default, but is hidden on the page. I have the Select link enabled on
my GridView, and I use the SelectedIndexChanged event to hide the
GridView, update the SelectCommand on my datasource with the
SelectedIndex, and finally show the FormView. This all works
beautifully, and I get my FormView populated with the data from the
selected Index shown on the page.

The code to handle this is fairly simple, and looks like the following:
(with the bulk of the query removed for readability)

protected void GridView1_SelectedIndexChanged(object sender, EventArgs
GridView1.Visible = false;
FormView1.Visible = true;
dsPackageEdit.SelectCommand = "SELECT ... WHERE [ID] ="

I want to do the essentially the same task for an Insert template as
well, which seems like it would be even less work to accomplish. The
InsertCommand is already defined, so essentially I want to just set the
mode to Insert, hide the GridView, and show the FormView. My resulting
attempt at this looks like the following:

protected void LinkButton1_Click(object sender, EventArgs e)
GridView1.Visible = false;
LinkButton1.Visible = false;
FormView1.Visible = true;


However, in practice, the first 3 commands execute fine, and both the
GridView and the button are hidden, and the mode on the FormView is
indeed changed to Insert, but the line to display the FormView again is
not successful, and I end up with essentially a blank page.

I've scratched my head on this for a while, seeing as I have 2
functions performing essentially the same task, where in one
FormView.visible = true works perfectly, but in the other, it does not.
Is there a reason why this would behave the way it is? Or is there
perhaps a more graceful way to approach this entire situation?

Your time and assistance is greatly appreciated.




I'm still a little confused over this occurrence. I've looked into it
in every way possible, but I'm apparently overlooking something. Any
assistance would be very much appreciated.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question