Passing value from one control to another and inserting that value in a table

Hey all, sorry if the subject is confusing or has already been covered, but I have (obviously) a problem (at least one).

This is using:
Visual Studio 2005
SQL Server 2005 Express
Visual Basic

I'm building a CRM system for my company and have run into a snag when attempting to add new customer records for a given client. The first thing that any CSR (or admin) must do upon accessing the CRM system is choose which client's customers they are actually working with (we have multiple clients and are ultimately responsible for providing customer service to the clients' end users), by selecting the client from a drop down list, which is bound to the ClientList Table. The text displayed in the drop down list (DropClient) is the value in ClientList.ClientName and the Value is the value in ClientList.ClientID.

Now, the problem comes when I want to enter a new customer. Each customer record (row) in the CustomerList table has 4 fields; CustomerID (primary key, autoincrements), CustomerLast, CustomerFirst, ClientID (foreign key tied to ClietList). CustomerList.ClientID does not allow NULL values, because we don't want random customer records roaming around in our DB unassociated with any clients. I am using the DetailsView control (detailsNewCustomer) to insert new records into CustomerList, and have the control bound to a SQLDataSource with the following SQL Statement:

SELECT * FROM [CustomerList] WHERE ([ClientID] = @ClientID)

Where @ClientID is DropClient.SelectedValue

What I ultimately need to know is how to instruct the Insert command to pass the following back to my DB:

1) CustomerLast = value entered by representative
2) CustomerFirst = value entered by representative
3) ClientID = @ClientID

Any help is greatly appreciated. 


- Tomarus Anguirel 

- Tomarus Anguirel
6/14/2007 8:22:47 PM 72751 articles. 1 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 32

Hi and welcome to the forums.

You are using DetailsView and Sqldatasource to insert a new record - right?  You can use the SqlDataSource's Inserting event to achieve this.  I have just showed how to change the value of ClientID parameter.  Change to suit your needs.


Sub On_Inserting(ByVal sender As Object, ByVal e As SqlDataSourceCommandEventArgs)

    e.Command.Parameters("ClientID") = DropdownList.SelectedValue

 End Sub 'On_Inserting
6/14/2007 10:28:41 PM

In sql datasource you need

InsertCommand="insert into CustomerList (CustomerLast,CustomerFirst, ClientId) values (@CustomerLast, @CustomerFirst, @ClientD)"


<asp:Parameter Name="CustomerLast" type="string" />

<asp:Parameter Name="CustomerFirst"  />

<asp:ControlParameter Name="ClientID" ControlId="DropDownList1" PropertyName="SelectedValue" Type="string? int32? or whatever" />



I assume CustomerList has an automatic id column, so we don't even need to mention that.

You have a DetailsView with the customer names, connected to your sqldatasource

You already have the Client selected in a DDL, so you don't need to repeat that in the DetailsView.

The <asp:Parameter ...  items refer to fields in the detailsview

The <asp:ControlParameter ...  refers to the ClientID, which is in a different control. 


I am assuming you do NOT have optimstic concurrency, with "original_..." parameters, turned on.

If a post helps to solve your problem, please click the Answer button on that post.

I'm still confused, but now I'm confused on a higher plane.
6/15/2007 10:40:12 AM

PS - it might help you if you look at the quickstart pages about sqldatasource and the gridview, detailsview and formview controls,

and work through Scott Mitchell's excellent data tutorials

(but maybe don't do the three tier user interface/business rules/data access stuff until you are comfortable with sqldatasource, everybody seems to get lost and confused with that at first, so skip the first three, concentrate on how the data presentation controls can be used. Then go back to the 3-tier stuff when you are ready).

If a post helps to solve your problem, please click the Answer button on that post.

I'm still confused, but now I'm confused on a higher plane.
6/15/2007 10:50:28 AM

Similar Artilces:

Pass 1 control value to another control value
I have this form, is the detailsview, and in edit mode, I have a link that you click to open up a small dhtml window (not a new window but more like a layer so everything is on the same page).  When I select an item from the dhtml window, it puts the value into a textbox.  I then have a button I click and I want to pass that value from that textbox to the textbox in the detailsview.  When I click the button, the value is not passed. Here is the code I use for getting the value from the dhtml window and assigning it to the detailsview textbox: If e.CommandName = "pi...

Trying to pass values from one control to another control
I have 2 controls on my page. CaseList and Email Reviwer. CaseList contain a datagrid that when the button (5th column) is clicked 2 values should be passed to the email revier control. In the email Reviwer Control I have declared: I have: public void sendCaseIdCatId(int catid,int caseid) { ViewState["EmailReviewerCategoryId"] = catid; ViewState["EmailReviewerCaseid"] = caseid; } in my EmailReviwer control   I tried: //Display the email reviewer panel EmailCaseReviewer.Visible=true; string strcatid = e.Item.Cells[1].Text.ToString(); string strcaseid = e.Item.Cells[0].Text.T...

How to pass control values from one ascx user-control to another???
Our site is set up using a primary default aspx page that is used as the "base page" for everything. On this page, we dynmaically place various user controls at run-time. This gives us a functionality similar to using frames where the outer-frame actually just sits there while various webfiles are loaded inside of it. Works great except for one thing... trying to figure out the best way to pass control names/values accross user controls. When the same usercontrol is posting back to itself this is a non issue. So far most of our functionality has worked well using the local...

Pass value from one User Control to another User Control
I have tried to pass value from one user control to another user control. Because of Page Auto Postback, Contrls are load before page is loaded. So I get the value in 2nd UC after one more post back operation. I have visited many suggessions but I cant solve this. Is anyone can help me to solve this. Thank U Muhmmad Fakhrul HossainEmail: mfhossain@gmail.comPhone: +88 01715 111512Web: You'd have to do that through the parent probably in it's Page_Load event handler.   userControl1.publicProperty = userControl2.publicProperty;  ...

Setting control values from one user control to another
I have two user controls on a page.  Control 1 is view. Control2 is search.  User selects value on Control2 and I want to update Control1(View).  I cannot find syntax to change values on Control1 from Control2.  The following is function on Control1 that is called from Control2 after pageInit and load on Control1.  I have tried many many ways to findControl but all fail. 'Function on Control1 called from Control2 after Control1 PageInit/load:         Public Function loadForm...

Control.Value and Control.SelectedItem.Value
Can someone explain to me the difference between say, Dropdownlist.SelectedItem.Value and Dropdownlist.SelectedValue?? Just curious, Thanks!Tim These are going to return the same thing. dropdownlist.selectedvalue is a shortcut to get the currently selected value in the dropdown. If that is all you want then you can just use that. If you want to access the currently selected item you can use dropdownlist.selecteditem and that return the item and you can then access any of the item's properties, including in this case the value property. If this post answered your question please r...

change format of one control based on value of another control
Hi, I am very new to and need some help with an odd requirement.  We use Visual Web Developer for all our work and have built our corporate intranet around it.  On our home page we have a hyperlink to our IT departments status page (traffic light system), we want to change the colour of the hyperlink text to be the same as the most serious traffic light on the other page (may be even flash the text for "red" issues)? Our IT department directly edit the traffic light network status page themselves, via a text editor, so the hyperlink on the home page needs to pic...

To pass values from one user control to another
Hi,       I have a page where there is a user control. inside that user control(let's say Usercontrol1) i have another user control(lets say Usercontrol2). in the usercontrol2 i have a tree and a button. When the page gets loaded first the treeview in the usercontrol2 should not get populated only when i click on a button in the Usercontrol1, then only the treeview in the Usercontrol2 should get populated. also i want to pass the text of a selected treenode when i click on the usercontrol2's button to a textbox in the userc...

pass value from one user control to another
i have a web page (Page.aspx) that contains a main user control (Main.ascx) which has two other controls within it (A.ascx, B.ascx). I have a text box and a button in A.ascx, when the user clicks the button i want the text in the textbox to be captured and then displayed on B.ascx. I have seen a few discussions on this using RaiseEvent but I'm not sure how to do it. Does anyone have any ideas? check this tutorial in codeproject thanks rasheeda, this post helped me out alot also. ...

How do you pass a value from one user control to another?
There must be an example of this somewhere but if there is I can't find it. I have a web form containing 2 user controls. The first displays a list of people. The user selects the person they are interested in and details of that person are to be displayed in the second user control. What is the best way of passing the selected item from the first user control to the second. I can do it with session variables, but there must be a better way than that. thanks You can use properties for that.User Controlprivate string m_Person;public string Person{    get {...

Passing values from one web control to another.
I'm trying to pass a value from one user control to another. Basically, the first user control selects an id number and then the second user control takes that id number and updates a record in a database. I have the second control set up to accept values using public string idnumber; public string IDnumber { set { idnumber = value; } } The second user control has two buttons that do postbacks, depending on which is clicked, a value is updated in the database identified by this number. The problem I am having is that before I click th...

insert multiple values from one table into one column from another table?
Hi, I'm attempting to create an insert statement that gets the values from multiple columns and insert them into one column from another table, is there a simple solution to do this?Here is something similar to what i'm wanting done, just it's not the correct way to do it, i want value1, value2 and value3 from one table to be combined and put into the value1 column of another table, what am i doing wrong? INSERT INTO tablename2 (value1 + value2 + value3)SELECT value1FROM tablename1 thanks in advance! INSERT INTO tablename2 (SELECT val1 + val2 + val3 FROM tabl...

How do I control one control from another control?
I have a page page1.aspx which is within a master page. On page I have a table with two cells. Within each cell I have placed two controls (ascx) that I have developed. Now I'd like to be able to get these two controls to interact. One needs to update the other. One has some search criteria that the other one needs to update its gridview. One needs to make the other visible/not visible at certain times. Out of the box neither control can see each other at all. Is there a good article or someplace I can find some information on how to do this? Information Technolo...

Pass values from one user control to a user control on a different aspx page
Hello, I have an aspx page titled Search.aspx. Within this page, I have a user control titled Search.ascx. I want a user to input search terms, then on the click of a button, I want to pass the values to another page (SearchResults.aspx)....which will then display the results in a user control. Can someone please give me some suggestions on how to do this? Thanks a lot! Hello, what you can do is: inside ur usercontrol, create a method that returns a dataset or datareader. that is, since u are searching using the usercontrol, then the result of ur search will be return...

Web resources about - Passing value from one control to another and inserting that value in a table -

Inserting Kate
jurvetson posted a photo: the speaking GPS avatar that we came to love.. more prep photos below... You can hear her voice in the video compilation ...

Inserting the Galaxy Note 5’s S Pen backwards can permanently damage the device
One of the features Samsung highlighted when it unveiled the Galaxy Note 5 was the device's new S Pen slot design. The Note 5 features a spring-loaded ...

Inserting Slavery Into The Climate Debate
Chris Hayes compares the fight against fossil fuels to the abolitionist movement. He states plainly that “there is absolutely no conceivable ...

Samsung smart TVs inserting ads into third-party apps
... playback have pissed off a number of consumers. People with smart TVs from Samsung have been complaining that the electronics maker is inserting ...

Inserting images into Gmail could be so much better
When Google first launched the new compact compose window in Gmail, many of you might have noticed something annoying about inserting images. ...

Gawker tells Steven Crowder to "stop whining, take your licks, and accept that getting hit in the face ...
"... in the middle of an argument between billionaire-funded know-nothing ideologues and people whose livelihoods and stability are being threatened ...

Gmail's New Interface for Inserting Photos
Gmail has a new interface for adding images to a message. When you click the "insert images" icon, Gmail now shows all the photos highlighted ...

Now Samsung SmartTVs are interrupting users' videos by inserting random ads
... room. Now Samsung is dealing with a new headache: Gigaom reports that Samsung SmartTVs are interrupting users' own video content by inserting ...

Samsung SmartTVs are inserting ads into movies - Business Insider
Random Pepsi pop-up ads have been appearing when SmartTV users watch content through the device's third-party apps.

Resources last updated: 12/7/2015 8:18:14 AM