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

S

scartin

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)
Code:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs
e)
{
GridView1.Visible = false;
FormView1.Visible = true;
FormView1.ChangeMode(FormViewMode.Edit);
dsPackageEdit.SelectCommand = "SELECT ... WHERE [ID] ="
+GridView1.SelectedDataKey.Values["ID"];
FormView1.DataBind();
}
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top