473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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.ChangeMode(FormViewMode.Insert);
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.
-Simon

Jun 1 '06 #1
1 3838
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.

Jun 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: WebBuilder451 | last post by:
What is the best way, or at least a good way, to insert new rows into a datagrid for update? I was hoping to click a "new" button and have a new blank row come up ready to edit. thanks kes --...
1
by: msmcg | last post by:
I built a dataform using the VB.net wizard. I have two tables, with one relation, Parent to Child, linked on one common key. The dataform loads the data fine, and when I click on the Add button,...
5
by: HS1 | last post by:
Hello I have Win application used to add records into a table (called Clients) in an Access database. I use a DataGrid1 to present records in this table and use some TextBox(es) to display...
3
by: Michael | last post by:
Hi all : I want to add button , dtpicker and combo box into datagrid. I don't want use 3rd party and I want write my own columnstyles. any reference / site to teach me how to do it ? ...
1
by: Giorgio | last post by:
Hi, I have a dropdown menu with categories and when a category is selected the Gridview is binded with sub-categories. Then when a sub-category is selected a detailsview is displayed...
3
by: panget | last post by:
I am supposed to create a form with a flexgrid that should display all contents of my database books.mdb. I also added a button called "Add" which when clicked should display another form with...
1
by: archcool | last post by:
I want to display new empty text fields within the same form after selecting an option from a combobox. here is the form Filter by:todays date,from date ---- in a combobox when from date is...
0
by: Ed Dror | last post by:
Hi there, I'm using Wisual Studio 2005 Pro with SQL server 2005 Dev on XP SP2 I have two tables Generic Item table (GN_ID) PK Color Table (Color_ID) PK and GN_ID FK very simple one to many...
2
by: Dhruvit | last post by:
I am tring to piggy back on this code, but needed some help. I have a combo box, and I've defined an "Add" Command button. So once a selection is updated from the combo, the "Add" button needs to be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.