Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Any one help me i'm waiting for your reply......

this code is inserting but its take only one username..

<asp:DropDownList runat="server" ID="DropDownList1" DataTextField="username" DataValueField="username" >



foreach (ListItem item in DropDownList1.Items)

{

if (item.Selected == true)
{
using (SqlConnection sqlcon = new SqlConnection(CS))
{
sqlcon.Open();
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = sqlcon;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO Calendar (parti ) values (@parti)";
cmd.Parameters.AddWithValue("@parti", item.Value.ToString());
cmd.ExecuteNonQuery();
Posted
Comments
Abdul Samad KP 30-Sep-15 2:51am    
If you use dropdownlist then you can select only one item at a time. If you want to select multiple items then use listbox , so that the user can hold control key and select multiple items. Alternatively you can use CheckedListBox also
Member 12002894 30-Sep-15 5:54am    
listbox that is also taking only one value my condition is
foreach(listitem item in Listitem1.items)
{
if(item.selected)
{
//insert code
}
}
Abdul Samad KP 2-Oct-15 9:58am    
How many items did you select? If you want to select multiple items press and hold control key then select items.
Member 12003400 2-Oct-15 1:14am    
Dropdownlist can select only one value at a time. as you have used
if (item.Selected == true)
condition, it will take only one selected value. If you want to add other value from dropdownlist irrespective of it is selected, You can use DropDownList1.Items[0].Value to get data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900