Can't get database values to display in the default Insert form

HI,

I am using a GridView and a DetailsView and would like to be able to pre-populate about half of the form fields in the Insert screen of my details view from data in my database.

I am using a sqldatasource and storedprocedures (for the "getthedata" and the "insertthedata") and the functionality of those work just fine.  The only problem is that when the user clicks on the NEW link in the details view, all of the form fields are empty and I would like to pre-populate about half of them with the same data that pre-populates the EDIT screen of the details view.  The background on this is that my detailsview pulls data from two tables and the data from the second table (Locations) needs to be in the form fields when the user clicks on the NEW link to create a new record.  The plan is to have the user fill out the data in the blank fields in the first part of the detailsview form, and will type over any pre-populated data in the remaining form fields if appropriate.

The data for the detailsview is retrieved based on the user's selection in the gridview; and again, all of the data for all shows up just fine in the EDIT screen of the detailsview.

As a test, I converted one of the Location table data fields on the screen to a template field and made sure the InsertItemTemplate for that field had a bind on it, but the data still didn't show up in the form field when I clicked on the NEW link, yet the data shows up in the EDIT screen.

<InsertItemTemplate>

<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("ListingLocationPhone1") %>'></asp:TextBox>

</InsertItemTemplate>

 Any help would be greatly appreciated. Smile

 

0
vtsnowrider
1/21/2008 10:22:15 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

4 Replies
697 Views

Similar Articles

[PageSpeed] 34

I don't know your table structure so I'll use typical example.

Let's say you have a table that has data in it, call it Orders, and a table that has customer data, call it Customers. Say the Orders table has a CustomerID that is a FK to Customers. When you go to edit an Order, the CustomerID that it is bound to is Orders.CustomerID. When you go to insert, if you wanted it pre-filled, it would need to come from Customers.CustomerID because the order doesn't exist yet.

You see the difference? You have to bind to Orders for the insert to work, but if you wanted it pre-filled with a CustomerID, you'd need to handle that as the grid went into insert mode and populate it from the Customers table.

You have the same issue here. It can't bind to both existing and non-existing data at the same time. Bind is a two way operation - it is bound so that when you go to insert it knows which field to insert into. But since there is no data yet, it's empty.

Does that make sense? 

You can pre-fill the textboxes when the grid goes into insert mode by setting the Text property appropriately. 


Please Mark As Answer posts that helped you.

"If we learn from our mistakes, I should be brilliant by now."

0
nikki_doer_of_things
1/22/2008 1:18:53 AM

Thanks for your quick reply.  I think I follow what you're saying, however I thought I had set the Text property appropriately to pre-fill the textboxt when the gride goes into insert mode by putting the text property on the InsertItemTemplate field.

<InsertItemTemplate>

<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("ListingLocationPhone1") %>'></asp:TextBox>

</InsertItemTemplate>

My parent table with the primary key of "ListingLocationID" is called "LISTINGLOCATION" and the child table is called "LISTING" and has a primary key of ListingID and a foreign key of LocationID. 

Here are my DetailsView control settings:

<asp:DetailsView ID="ListingDetailsView" runat="server" AutoGenerateRows="False"

DataKeyNames="ListingID,ListingLocationID"

DataSourceID="ListingDetailsDataSource"  >

 

Here is my SqlDataSource:

<asp:SqlDataSource ID="ListingDetailsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MYDBConnectionString %>"

SelectCommand="usp_getlistingdetails" SelectCommandType="StoredProcedure"

UpdateCommand=usp_updatelistingdetails UpdateCommandType=StoredProcedure

InsertCommand=usp_addlisting InsertCommandType=StoredProcedure

 

>

Here is my stored procedure:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_getlistingdetails]
 @SubcatlistingID INT
 
AS

BEGIN

 SET NOCOUNT ON;
   
SELECT *
FROM Listing
INNER JOIN ListingLocation ON (Listing.ListingLocationID = ListingLocation.ListingLocationID)
WHERE ListingID = @ListingID
END

You said "You can pre-fill the textboxes when the grid goes into insert mode by setting the Text property appropriately" but since I thought I did that through the Text Bind property on the InsertItemTemplate for the field, then how can I "pre-fill the textbox when the grid goes into insert mode?"  Could you give me an example of how to do that?

 

 

 

 

0
vtsnowrider
1/22/2008 2:06:22 AM

 Hi vtsnowrider ,

As nikki says,It can't bind to both existing and non-existing data at the same time. Bind is a two way operation - it is bound so that when you go to insert it knows which field to insert into. But since there is no data yet, it's empty.

If you really want to pre-fill some values in insert mode, you can write some codes in PreRender event of DetailsView control.

something like:

 

        protected void DetailsView1_PreRender(object sender, EventArgs e)
        {
            if (this.DetailsView1.CurrentMode == DetailsViewMode.Insert)
            {
                TextBox box = this.DetailsView1.FindControl("TextBox3") as TextBox;
                box.Text = "value in edit mode";
            }
        }
 

Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
1/23/2008 9:28:58 AM

Thanks, but I'm not sure what you mean by "value in edit mode".  What syntax would I use to retrieve that edit mode field data?  Would it be:

box.Text = @formfieldname

 

0
vtsnowrider
1/25/2008 6:32:58 PM
Reply:

Similar Artilces:

I can't get no cache, I can't get no cache. 'Cause I try and I try and I try and, I can't get no, I can't get no cache.
I have fiddled out for days tinkering with the setting in about:config trying to get FireFox 12 to use the disk cache. I have NOT found the trick. This One Trick Pony ain't doing it like it used to up until recently. Pray tell anyone, What information can I share that will point a knowledgeable person to aid me in getting FF to disk.cache? I have also tried restarting FF with add-ons disabled, (There were NOT too many to do this to, so it was quick and easy) Here is my stab at trying to convey the information that MIGHT govern matters Using about:cache Informatio...

Re: I can't get no cache, I can't get no cache. ' Cause I try and I try and I try and, I can't get no, I can't get no cache.
<div>please com e see me about htis<br /> <br /> ------- Original Message f= rom the Global Relay Archive -------<br /> From: Hp &lt;ferd@farkel.net&gt;= <br /> To: "support-firefox@lists.mozilla.org" &lt;support-firefox@lists.mo= zilla.org&gt;<br /> Sent: Sun, 27 May 2012 18:30:18 -0700<br /> Subject: I = can't get no cache, I can't get no cache. 'Cause I try and I try and I try = and, I can't get no, I can't get no cache.<br /> <br /></div> <pre class=3D"gr-maex-body-pre&qu...

Two things,Why do I keep getting emails that I don't want. can't get rid of them? Why can't I get my email when I am out of town? Or can I?
Name: Ed Leech Email: ELCraftatzoominternetdotnet Product: Thunderbird Summary: Two things,Why do I keep getting emails that I don't want. can't get rid of them? Why can't I get my email when I am out of town? Or can I? Comments: I am getting frusted with all the emails coming in that I do not want, I am using the tools to get thme out but they keep coming. They just use different names or whatever. I have been thinking of just switching to something else but my business intrusts know this email and it is tooo confusing to change. Every time I go out of town on bu...

2010: Can't register - can't download the software - can't register until I have the software
I have active maintenance on Rad Studio: From: Vicky Rassmisaengthong [mailto:Vicky.Rassmisaengthong@EMBARCADERO.COM] Sent: Wednesday, February 25, 2009 1:58 PM To: rgrossman Cc: amer.supportadmin@codegear.com; Ashley Cosentino Subject: Software Assurance Support for Tech III Inc PO# Credit Card Dear Embarcadero Technologies Support Customer, Welcome! You have been registered as the primary contact on support account number AM####### Herewith we confirm your Embarcadero Technologies support agreement covering: Qty 1 RAD Studio Enterprise Named User licens...

Trying to edit web form, can't get database updated with newly edited values.
 This is my code:  when I try to update any of the fields, the update statement retains the old values retrieved from the database.  Could you tell me where my code is bad? -Thanks, Mark   <%@ Page Language="VB" %><%@Import Namespace="System.Data"%><%@Import Namespace="System.Data.SqlClient"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> Protected Sub Page_Load(ByVa...

Can't update my database because I can't retrieve the value from radiobuttonlist
Hello I am a beginner in ASP.NET and I am now developing a poll application but I had a problem and I could not solve it. The problem is that I could not use an update query because my SQL statement cannot retrieve the value from radiobuttonlist . I am now stack in this point and I could not complete my application. I could not  attach the website because I am not allowed. I don't know why. Note : the error message is  No value given for one or more required parameters.   My CODE : Conn.Open() Cmd3 = New OleDbCommand("Update PollAnswer Set PollCount = PollCount + 1 Where...

I can't get current default value from DataTableReader, How can I do ?
I would like to check current structure especially "default value"However after I use DataTableReader to get structural value from any table , there was only null value   How can I get structural value from real table in database with others method ????  Please help me ?  Hi, I'm not clear what you want. But if you want to navigate the contents of a DataTableReader ,try the following articles. http://msdn2.microsoft.com/en-us/library/z071789y(VS.80).aspx Thanks.Michael Jin.Microsoft Online Community SupportPlease remember to mark the...

Can't insert OLE controls. GPF when accessing
Hi all, I'm running PB 9 (6533) on Wndows XP and having problems when trying to insert OLE Controls. PB crashes when clicking on the Tab "Insert Control" in dialogue "Insert Object". PB 10 beta works fine and PB 8 crashes like PB9 (all on the same PC). Does anyone have any clue how to solve this? /Thanks! I am having the exact same issue in PB8 on windows XP. I noticed that no one had a reply so I was wondering if you were ever able to resolve the issue. Thanks ...

Can't get it to work. Can't get help.
Name: Tony Clarke Email: minionataondotat Product: Thunderbird Summary: Can't get it to work. Can't get help. Comments: Installed T'bird. Had to change defunct server that T'bird selected by default. Kept asking for passwords associated with previous email (Outlook Express ), when passwords entered then got error messages saying aon responded with 're-authentification failure'. Searched your knowledge base & help forums to no avail. Found them very user-unfriendly & ended up more confused than before. Would like to try T'bird, but I think ...

XE5 can't install abbrev library -- missing designide, can't compile empty form -- no control.res
WTH!!! When I first installed XE5 about 6 months ago I was able to create a blank form and compile it -- and it made a 10meg empty file. After calling tech support I was able to get it down to 2 megs. Yeah! Now after two updates, I get an error "missing controls.res" file. Sorry, I'm still working primarily in D2007 which actually works. I wanted to try the new one and can't get anywhere. I also tried to install some components. virtual trees installed ok. Jedi will not compile jclutils.pas unit, abbrev says it's missing designide unit. I still have a h...

update fails, can't get out of it and now can't get my email
Name: martha Email: mjhartleyatchampmaildotcom Product: Thunderbird Summary: update fails, can't get out of it and now can't get my email Comments: The directions about bugging aren't helpful to me because I don't know what you're talking about. You offered an update, I tried it, now it is in an endless loop of trying to install, failing, and trying again. It is very frustrating because I can't even get into my old email files to get addresses, photos, etc. I have turned off my firewall and have rebooted the computer, per some of the suggestions in the...

Default value for Dropdownlist that get's it's value from Database.
Hi, I am using an Object Data Souce to retrieve the value of a Dropdownlist from a table on MS SQL server 2005. I want to make a default value appear on the Dropdownlist intially, should i enter the default value into the database table or is that a better way of doing it? Any suggestions will be very much appreciated. E  No need for database just set sekected value after databingind protected void Page_Load(object sender, EventArgs e) { DataBind(); ListItem defaultItem = new ListItem("Select a Person", "-1"); th...

Can't get away from: "Could not open in Design View. Quote values differently inside a '<% ... "value" ... %>' block."
I keep getting this error message when I try to switch to design view. This is the code that is causing it. OnClick="javascript:void(0);ToggleRowDisplay(this,'row<%# DataBinder.Eval(Container.DataItem, "Equipment_ID") %>');" When I take out this section I can go into design view without a problem. Any ideas?? is the word row has to be there?mess with the best...die like the rest...

Can't get through init 3 from init 5 and can't get through init 5 from init 3.
I tried opensuse 12.1 Gm today. Installation was perfect with xfce 4.8 until I tried installing the nvidia driver. In runlevel 5 as superuser I tried to shift to runlevel 3 and was welcome with a black screen, I have to use ctrl-alt-delete to reboot. During the reboot I used runlevel 3 and I was able to install the nvidia driver. After the nvidia driver installation I tried to shift to runlevel 5 and there, I was welcome with a black screen with a stationary blinking x cursor. I rebooted once again wiith runlevel 5 to get the gui. Any one had seen this happened? This installation is...

Web resources about - Can't get database values to display in the default Insert form - asp.net.presentation-controls

Resources last updated: 12/20/2015 12:42:48 PM