Hi friends,
i have a checkboxlist with multiple selections connected to the database.
but it just stores one value.
i want to store multiple values.
Can you please help me out???????
11 2838 <asp:CheckBoxList> control, by default, is already a multi-selection control. I guess, it may be the problem of how you have its data binding or select value... Erm...
Please post your codes, perhaps part of your codes, so that we can understand your scenario further. Thanks... : )
Also, is this a Windows Forms app, or an ASP.NET website?
i have no idea abt the code.... i just know we hav to use loop for it....
n im doing it in ASP.NET (.aspx & .aspx.vb)
Hi, sandeepv. I think a loop plays a major role in solving your problem. Somehow, different implementations for different scenarios. More information is needed in order for us to understand your issue further... : )
Give us some hints, such as:
- Do you place your CheckBoxList within another control such as GridView, FormView, etc?
- Do your CheckBoxList populates its list items based on a list of hard-coded values or dynamically from a database table?
- What is your database tables' structure? Do you store your selected values as a comma separated list within a single field? Or do you store your selected values in a separated table?
- How do you access to database? Manually create your Connection, Command and DataReader objects? Or just by configuring a SqlDataSource control?
- etc...
Without some of these details, none of us can start our first step to help you further. Hope to hear from you soon... : )
thankyou for responding.
will specify exactly how i was thinking abt my situation....
Suppose i have a database named test with one attribute.
i have a plain checkboxlist i.e no gridview etc.
suppose there are 5 items in the checkboxlist
my question>if the person clicks on the 4 items in the checkboxlist then i want to save those 4 items in the attribute in the database
pls help me out....
Suppose you're using MS Access database (named Sample.mdb and located at the App_Data folder of your Website), and the TEST table consists of 2 fields: TEST_ID (PK, auto number) and TEST_ITEM (text).
Suppose a user is to select some items from the CheckBoxList cblTestItem. If he clicks on the button btnInsert, the selected list items will be formatted as a comma-separated string, and to be inserted into the TEST table's TEST_ITEM field as a new record. -
using System.Data.OleDb;
-
...
-
protected void btnInsert_Click(object sender, EventArgs e)
-
{
-
// 1. Get the selected items and format as comma-separated string
-
ArrayList list = new ArrayList();
-
foreach (ListItem i in cblTestItem.Items)
-
{
-
if (i.Selected)
-
list.Add(i.Value);
-
}
-
string[] arr = (string[])list.ToArray(typeof(string));
-
string test_item = string.Join(",", arr);
-
-
// 2. Insert into database
-
string cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|Sample.mdb";
-
string sql = "INSERT INTO TEST (TEST_ITEM) VALUES (?)";
-
OleDbConnection con = new OleDbConnection(cs);
-
OleDbCommand cmd = new OleDbCommand(sql, con);
-
cmd.Parameters.AddWithValue("", test_item);
-
con.Open();
-
cmd.ExecuteNonQuery();
-
con.Close();
-
}
-
The code above is to give you some basic ideas about how the job can be done. Change (connection string, sql, etc) and enhance (try-catch, message, etc) the logic based on your needs... : )
thankyou the code and explanation.
can you pls tel me the code for SQL Server???
SQL Server? Generally... : ) -
// using System.Data.OleDb; <-- replace this with
-
using System.Data.SqlClient;
-
...
-
// string cs = "Provider=Microsoft..."; <-- replace this with
-
string cs = "...";
-
// where ... is connection string for SQL Server
-
I think you may have to do some basic study on database access on your own. Cheer... : )
We have two articles on using DBs in your .NET programs on this site. I suggest you read them both if you don't know how to use DBs in your program:
im sorry the previous reply of mine was incomplete....i know the SQL connection....just wanted to know something else...
wanted to know the aspx.vb script for the code u have specified.....
as list.add() doesnt work in aspx.vb
thankyou
Erm. Get your point... : )
Here is the VB.NET version of manipulating the ArrayList: - ...
-
Dim list As New ArrayList
-
For Each i As ListItem In cblTestItem.Items
-
If i.Selected Then
-
list.Add(i.Value)
-
End If
-
Next
-
Dim arr() As String = list.ToArray(GetType(String))
-
Dim test_item As String = String.Join(",", arr)
-
...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dennis Johansson |
last post by:
I have a CheckBoxList like this one:
<asp:CheckBoxList id="chkReport" runat="server" DataValueField="rptID"
DataTextField="RptName" Enabled="False"
RepeatLayout="Flow"></asp:CheckBoxList>
I...
|
by: dm_dal |
last post by:
Is there a know issue surrounding the CheckBoxList control and it's
viewstate?
When my control is created, it's ListItems are checked as needed, but on a
postback, they loose their Selected...
|
by: JD |
last post by:
Hello,
I have a problem with checkboxlist inside Repeater (in ASP.NET page).
I am able to create Checkboxlist and bind it (inside Repeater_ItemBound -
including setting checked/unchecked)....
|
by: Dune |
last post by:
Hi,
Is there anyway to get the datavaluefield from a databound checkboxlist
using javascript?
If not, is there any way to associate a custom attribute with the databound
checkboxlist items so...
|
by: Patrick.O.Ige |
last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in
a Datalist)
By doing "li.Selected = True" i can see all the checkBoxes are selected.
But what i want is to be able...
|
by: Patrick.O.Ige |
last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected
after doing a postBack.
I have set my CheckBoxlist AutoPostBack="True"
Any ideas what 'm doing wrong?
It seems not to...
|
by: ThunderMusic |
last post by:
Hi,
I have a CheckBoxList and I want to add some javascript code to each
CheckBox created by this CheckBoxList. I tried iterating through all items
of the list, all the controls, do a FindControl,...
|
by: webmaster |
last post by:
Hi all,
I'm tearing my hair out with this one.
I have successfully implemented by own RadioButtonList in order to
provide additional functionality and a DIV rather than TABLE-based
layout in...
|
by: haresh.amis |
last post by:
hello to all,
I m using .net 2.0 and i face a problem that is as under
Well I have a checkboxlist which i bound in .cs page
now I want to count that how many checkboxes ate checked ( In...
|
by: mercea |
last post by:
hi all,
i have a grid view and i have inserted a checboxlist template with 5checkboxes per row into the gridview. i want the user to be able to select an option (A-E) and that selected option be...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
| |