CheckBoxList gets text from one table, send values to another table

I am working on making a CheckBoxList in a DetailsView that allows the user to check the boxes of the services they would like to receive.  In my SQLDataSource, I have two tables that are involved in this.  Columns "ServiceID" and "Name"are stored in one table, "Services," and the columns "UserID" and "ServiceID" are stored in another table, "UserServices."  I want the CheckBoxList to grab the value and the name of all the services available and have a box for each with the name beside each box.  Once the user clicks on each box they want and then click "Submit" I want all rows in table "UserServices" with that user's ID to be erased, and then add all the services that were checked (the reason to erase all and re-insert is too keep from having to check for duplicate records).  How do I go about doing this?
0
subtleSuburbia
8/7/2006 7:54:03 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

3 Replies
764 Views

Similar Articles

[PageSpeed] 17

Can you post your declaration of SqlDataSource.
0
codeasp
8/7/2006 9:04:19 PM
I'm sorry, I guess I should've clarified that my SQL is also somthing that I have gotten stuck on.  I'm not sure how to make it so that it grabs the info only from the first table, but places the values into the second table.
0
subtleSuburbia
8/7/2006 9:36:05 PM
1.  Use a SqlDataSource to get all the Services from your Services table and bind it to the CheckBoxList.  Example: 
<asp:CheckBoxList id="CBL1" runat="server" DataSourceID="SDS1" />
<asp:SqlDataSource id="SDS1" runat="server" ConnectionString="YourConnectionString" SelectCommand="SELECT ServiceID, Service FROM Services" />

 2.  In the Click event of the button (where user wants to change his preference of services), you can provide the logic for updating.  Because you want to update number of records (with different values) you have two options.

a) You can update records one at a time calling the stored procedure/or raw sql 

"SDS2" runat="server" UpdateCommand="Update UserServices SET ServiceID = @ServiceID WHERE UserID = @UserID" />
 In the code-behind 
for each item as ListItem in CBL1.Items
   if item.Checked
       SDS2.UpdateParameters.Add("ServiceID", cint(item.Value))
       ' Also add the UserID param
       SDS2.Update()
   end if
next item

 b) Other option is to send all ServiceID as delimited string and in the stored procedure get the value of the delimited strings and then update.  Hope this helps or atleast get you started.

0
codeasp
8/7/2006 10:23:47 PM
Reply:

Similar Artilces:

Getting information from one table and applying it to another table record.G
Hello, I'm creating a website in ASP.NET and C#, My problem is I want to add a new record to a table using data from another table. i.e. Add a book, to set the book category you have to select if from a databound dropdown in another table. All those categories are stored in a different table. I'm not sure how to do that. Any help is appreciated. Thanks a lot!! Gabriel do datasource copy in the server-side or javascript copy in the client-sideRichard Tsuei (Chikun Cui)Contact me via E-mail: ricktsuei@gmail.comWeblog: http://ricktsuei.cnblogs.com+-+-+-+-+-+-+-+-+-+-+-+-+-...

is there an sql statement to insert data to one table and getting the data from another table
Ok I have a table that have general categories with just name and CatNo. Now what I want to know is when I create a client to move all the data in general categories to another table called categories that have the clientid to associate it with the client. I would appreciate for any help what is your question here??Shravan Addaypally MCP...

How to get one database table data in to an input form to put info in another table.
The table data to pull from is place on the same page as the input form, it is also the same number used as the URL Parameter, so if I coiuld pull it from there it would be easier, what code do I need to do this in my input form? You will need two simple scripts set up. The first will bind the data to your form controls when the page loads. The second will insert the data from the form into the database. The syntax will vary a little depending on your database type and the language you want to use to create the code. Check out this tutorial for how to do all it is you need to know re...

How to get text from one textbox into a particular column of an another table
Hi i am creating a simultor using XUL, in that simulator i have included editor and debugger. For editor i am using the text box and for the debugger i am using a table which include tree row and tree cols . If i enter the program in editor it have to print the it line by line in source code(column) of the debugger . Can any one help to solve it . ...

Why would one table be getting corrupted more then any other table?
We are finding that one of our tables is getting assertion errors much more then any of our other tables, there are about 100 tables, but the database corruptions seem to be grouped around this one table. The complete error is General error: Internal database error *** ERROR *** Assertion failed. 50213. Page number on page does not match -- transactions rolled back. ODBC SQLSTATE = S1000. Database Error Code = -301. We are currently running a PowerBuilder 5 app using SQL Anywhere 5.5.03. This problem was occuring in our PB 4 app which used SQL Anywhere 5.0.02. What happens is that...

Why would one table be getting corrupted more then any other table?
We are finding that one of our tables is getting assertion errors much more then any of our other tables, there are about 100 tables, but the database corruptions seem to be grouped around this one table. The complete error is General error: Internal database error *** ERROR *** Assertion failed. 50213. Page number on page does not match -- transactions rolled back. ODBC SQLSTATE = S1000. Database Error Code = -301. We are currently running a PowerBuilder 5 app using SQL Anywhere 5.5.03. This problem was occuring in our PB 4 app which used SQL Anywhere 5.0.02. What happens is that...

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...

getting user name from another table (id included in another table)
Hi,  I am using a datagrid and I have 2 tables (I will try to explain as simple as I can) ... First table contains SENDER_ID and TOPIC fields . The sender id's are the users Id's. Second table contains member records and Lets say it has it has MEMBER_ID , MEMBER_NAME columns. I get the values from first table to datagrid and I want the SENDER_ID 's to be converted to MEMBER_NAME 's  while displaying the data with datagrid . I am able to do this but I have to connect to db for every MEMBER_ID record to transform them to names .Here it is &lt;ItemTemplate&gt;&lt;%# ...

Get records from one table and insert into another one
I make that but I did not work, thanks  SqlCommand cmd2;cmd = new SqlCommand("SELECT CS_ID FROM Tbl_Conselheiros WHERE CS_TIPO IN (5,6,7)", conn); dr = cmd.ExecuteReader();  while (dr.Read()) {cmd2 = new SqlCommand("SP_PRES_GRAVAR", conn); cmd2.CommandType = CommandType.StoredProcedure;SqlParameter id = new SqlParameter("@ID_CONSE", SqlDbType.Int, 4);id.Value = Convert.ToInt32(dr[0]); cmd2.Parameters.Add(id);SqlParameter data2 = new SqlParameter("@DATA", SqlDbType.VarChar, 8); data2.Value = FormataData(); cmd2.Parameters.Add(data...

Getting "Problem in Mapping Fragment starting at line ..." error when trying to create table mappings for table associations in ADO.NET Entity Framework
 Table A: COUNTRY_LOOKUP COUNTRY_ID   smallintclustered, unique, primary key located on PRIMARY    COUNTRY_ID TABLE B: COUNTRY_MODE_RULES CARRIER_ID    intMODE_RULE_TYPE_ID    intORIG_COUNTRY_ID    smallintDEST_COUNTRY_ID    smallint clustered, unique, primary key located on PRIMARY    CARRIER_ID, MODE_RULE_TYPE_ID, ORIG_COUNTRY_ID, DEST_COUNTRY_IDThere is a foreign key relationship from COUNTRY_MODE_RULES to COUNTRY_LOOKUPORIG_COUNTRY_IDREFERENCES .COUNTRY_LOOKUP (COUNTRY_ID)DEST_CO...

How can I get a value from a table, then store a related value in another
I hope I can explain this with some degree of sensibility. First, this is a fairly simple Master/Detail page with GridView and  DetailsView controls.  GridView1's SqlDataSource1 uses a sql view that joins two tables (tblMain and tblEmployees) on UserId and adds a UserName column to the grid.  GridView1 filters on invisible Textbox1 which has been populated with the currently logged in user's name via Textbox1.Text = User.Identity.Name DetailsView1 filters on the current SelectedIndex of GridView1, and provides New, Edit, and Delete functionality on tblMain data from SqlDat...

how to Get data from one table to another
I have three tables: Vendors, Vendor_Cat, Bid_Cat_Lookup. Vendors_Cat is just a table that contains a VendorID from Vendors and a Bid_Cat_ID from Bid_Cat_Lookup. What SQL verbage do I use to get these ID field variables from Vendors and Bid_Cat_Lookup into my Vendors_Cat table. Is this just a one time thing to transfer data into those tables? Are you just matching the vendorID with the appropriate vendor category ID? This, to me, just seems like something you have to manually match up by using an online interface you build, or by manually doing it in the database.Chris Paterra ...

getting data from one table to another
im taking data from gridview to database table. while the number of columns in gridview is only few, the actual dtaabase table has many columns. when a user first creates a user, it asks for other pieces of information like industry and sector and creates an Id for that user which are all stored in different table. when i wish to take data from gridview to table i need to pull data (industry, sectore and userId) out from other table. how can i do this? thanks all. Hi,Do you want ot show your user data in datagrid ?If so , then you create query with the use of inner join.Mark as...

How to only get one value from a database table
Hi I've just got started with ASP.NET. I'm trying to retrieve only one value from a database table but I don't know how to. I know I can display an entire table or selected fields using the GridView control but I don' want that. I don't want to display the value just use it in my code.  I would appreciate an example  Thankswww.LinkToIslam.net  Use Command.ExecuteScalar to get one value back from database. Silverlight-helpVb TipsSpace Coast .Net User Group Thanks. That works.www.LinkToIslam.net...

Web resources about - CheckBoxList gets text from one table, send values to another table - asp.net.getting-started

APNS Pusher, debug your push notification app - Coders Grid
Coders Grid your best development resources collections site Menu Skip to content Resource web development design stuffs guideline coding mobile ...

.NET sample code - developer Fusion
Discover the very latest .NET sample code Out of the box, the ASP.NET list controls (CheckBoxList, RadioButtonList, DropDownList) only support ...

ConditionalRequiredTextValidator Control
The ConditionalRequiredTextValidator control allows you to specify a CheckBox, RadioButton, CheckBoxList, RadioButtonList, DropDownList, or ListBox ...

Sports-Gazer - About Us
Sports-Gazer is an application for ranking and rating sports teams. It also can project scores for upcoming games. Certain parts of this application ...

Layar 3.0 mobile augmented reality browser launched
Layar, the world’s first augmented reality (AR) browser…

ASP.NET 4 and Visual Studio 2010 Web Development Overview : The Official Microsoft ASP.NET Site
This document provides an overview of many of the new features for ASP.NET that are included in the.NET Framework 4 and in Visual Studio 2010. ...

Gaiaware - Gaia Ajax
Home Samples Download Free Trial Buy from $195 Login Download Free Trial ASP.NET Done Right 6 reasons to use Gaia Ajax? 40 UI controls 10 aspects/behaviors ...

compass - Coders Grid
Coders Grid your best development resources collections site Menu Skip to content Resource web development design stuffs guideline coding mobile ...

APNS Pusher, debug your push notification app
Coders Grid your best development resources collections site Menu Skip to content Resource web development design stuffs guideline coding mobile ...

Buttons.css, a css library makes buttons beautiful - Coders Grid
Coders Grid your best development resources collections site Menu Skip to content Resource web development design stuffs guideline coding mobile ...

Resources last updated: 11/24/2015 9:06:25 AM