How To Insert List Box Items In One Column
Feb 8, 2011
Here is my code which insert listbox items table and create record.
protected void Button1_Click(object sender, EventArgs e)
{
ListItem li = new ListItem();
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source= C:Ruchitaweb" + @"WebSite527afcergonomic.mdb";
conn.Open();
for (int i = 0; i < ListBox1.Items.Count; i++)
{
li.Text = ListBox1.Items[i].Text;
}
OleDbCommand cmd = new OleDbCommand("insert into record(recorditem) values('" + li.Text + "')", conn);
cmd.ExecuteNonQuery();
conn.Close();
}
this is inserting in diffrent rows but i want this in one row with (,)so i can parse it and get it back which items user selected. and i also want to show messge box that show the record number.
View 5 Replies
Similar Messages:
Feb 9, 2011
i have added several items into a list box, but i m not sure how to insert the several items within the list box individually into the database..
for example,
- within my list box, i have apple, orange and banana.
- next, i would like to insert into database in different row -->
fruit name
apple
orange
banana
View 4 Replies
Jan 27, 2011
i defined an enum with the [flags] attribute and binded it to a checkboxlist.
my question is how can i insert the selected items to a list?
this is my code:
[Code]....
View 4 Replies
Aug 4, 2010
i use this to select one checkbox to isselected column how i convert this to multi checkboxlist to single column i use many ways more than 3 days without success
private void BindCheckBoxList()
{
DataTable dt = new DataTable();
SqlConnection connection = new SqlConnection(GetConnectionString());
try
{
connection.Open();
string sqlStatement = "SELECT * FROM boby";
SqlCommand sqlCmd = new SqlCommand(sqlStatement, connection);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
CheckBoxList1.RepeatColumns = 4; // set the number of columns in the CheckBoxList
CheckBoxList1.DataSource = dt;
CheckBoxList1.DataTextField = "Name"; // the items to be displayed in the list items
CheckBoxList1.DataValueField = "Name"; // the id of the items displayed
CheckBoxList1.DataBind();
//Setting the Selected Items in the ChecBoxList based from the value in the database
//to do this, lets iterate to each items in the list
for (int i = 0; i < dt.Rows.Count; i++)
{
if (!string.IsNullOrEmpty(dt.Rows[i]["IsSelected"].ToString()))
{
CheckBoxList1.Items[i].Selected = Convert.ToBoolean(dt.Rows[i]["IsSelected"]);
}
}
}
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Fetch Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
connection.Close();
}
}
private void Update(string name, bool isSelected)
{
SqlConnection connection = new SqlConnection(GetConnectionString());
SqlCommand cmd;
string sqlStatement = string.Empty;
try
{
connection.Open();
sqlStatement = "UPDATE handymen SET IsSelected = @IsSelected WHERE Name = @BizName";
cmd = new SqlCommand(sqlStatement, connection);
cmd.Parameters.AddWithValue("@Name", name);
cmd.Parameters.AddWithValue("@IsSelected", isSelected);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert/Update error";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
connection.Close();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindCheckBoxList();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string str = string.Empty;
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
str = CheckBoxList1.Items[i].Text;
Update(str, CheckBoxList1.Items[i].Selected);
}
}
//ReBind the List to retain the selected items on postbacks
BindCheckBoxList();
}
View 3 Replies
Dec 14, 2010
I am attempting to bind data from a dropdown list that was populated from another datasourceID. I've bolded what I believe is relevant to this issue in the code below. But basicly its binding the proper county on the pull down menu but when I hit form submit it dosnt postback that info instead its null.
[code]....
View 14 Replies
May 27, 2010
I have a situation where I want to show the selected records out of total records for a product of an employee
1) There is a checkbox list bind to <List> of objects from object datasource (For total items in list)
2) Now I want to check the selected items for a particular record in this list
3) For this purpose I have another list of <List> selected items returned by data access layer (For selected items for that employee )
4) How do I bind the selected objects with the total items list ?
5) In spaghetti coding model it was all too easy just by binding the checkbox list with a sql data source and running a for each on form load
View 5 Replies
Jul 8, 2010
I have a grid containing images loaded from database. the images are displayed in the order as they are stored in the database. Is there any way to change the order of the images manually once after they are uploaded to the database.. the admin before publishing the images to front end, should be able to arrange the images as he/she wish and then finally stores them in database.
View 5 Replies
Feb 6, 2010
I have the following Students class:
[Code]....
I need the 1 since it's a foreign key in another table. For the life of me, I can't get this to work like this.
View 7 Replies
Oct 17, 2012
Is it possible to set tab index value for list items of ASP.Net RadioButtonList control.
View 1 Replies
Feb 24, 2010
I'm designing my own custom control that contains a .NET dropdownlist. What I'm wondering is if it is possible to populate my dropdownlist with listitems placed in a placeholder? For example:
<asp:DropDownList ID="ddlFilter" runat="server" >
<asp:PlaceHolder ID="ListItemPlaceholder" runat="server"/>
</asp:DropDownList>
This doesn't work because the DropDownList control only allows ListItems as child controls. But, I want to do something similar to this so when the user includes my control on a page, they can do something like this:
<mytag:MyControl Mode="DropDown" runat="server">
<ListItemTemplate>
<asp:ListItem Text="C" Value="c"></asp:ListItem>
<asp:ListItem Text="E" Value="e"></asp:ListItem>
<asp:ListItem Text="B" Value="b"></asp:ListItem>
</ListItemTemplate>
</myTag:MyControl>
I know I can do this by dynamically adding the ListItems in the page code behind, but I'd like to avoid that if possible.
View 1 Replies
Mar 25, 2011
I am getting this error yet I know it to be untrue.This is the code:
ddlPartnerOrganisation.DataSource = agency.AgencyGetListOfEYDN();
string temp = ddlPartnerOrganisation.SelectedValue.ToString();
ddlPartnerOrganisation.DataValueField = "AgencyID"
;
ddlPartnerOrganisation.DataTextField = "AgencyName"
;
ddlPartnerOrganisation.DataBind();
View 4 Replies
Feb 5, 2010
Is it possible to select values from a List, where the items contain in a different list aswell?for example;
[Code]....
What I need are all the items from the first list "Items", where the string contains something from the second list "List".So I need something which returns the first 3 items (which contain the term "Item") from the first list.
View 3 Replies
Jan 18, 2010
I have a form with many form fields and controls, with some offering an "other" if a value does not meet the needs for the user. How can I bind the sql insert so that it will take the ddl selection along with the txt field selection for the "other" value? Even if the txt field is empty it should not be a big deal since the ddl would provide something other than null. Since the column in the db does not allow nulls. I'm using asp.net (vb) 3.5 sp1
View 3 Replies
Jan 24, 2016
How to handle this error
"An explicit value for the identity column in table 'UserActivation' can only be specified when a column list is used and IDENTITY_INSERT is ON."
View 1 Replies
Aug 10, 2011
I am trying to create a add all button to execute a query and insert all rows from a gridview.
Can't make it work, it only inserts one row.
vb Code:
Imports System.Data.SqlClient Public Class page1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object,
ByVal e As System.EventArgs) Handles Me.Load End Sub
[Code]....
View 3 Replies
Dec 15, 2010
I create a table as picture below :
when I insert any character to column Name then A new string random will auto insert into column Random (picture below) I had used Trigger but It was error !
I want to column Random use to code :
DECLARE @myid uniqueidentifier
SET @myid = NEWID()
insert into table_1 values(@myid, substring(CONVERT(varchar(255), @myid), 1, 5))
but It must auto like column Number (column Number is Identity)
View 1 Replies
Jan 18, 2011
I'm trying to populate 1000 ListItems in a ListBox.
how to do it. Currently only 100 items are being displayed even though I set the capacity of the ListBox to 1000.
Below is sort of how my code looks like. :)
listBox.Items.Capacity = 1000;
foreach(entity ent in enitityCollection)
{
ListItem listItem = new ListItem();
listItem.Value = ent.Id.ToString();
listItem.Text = ent.Name;
listBox.Items.Add(listItem);
}
entityCollection has 989 records in it.
Code does not generate any error. only that at the end of the loop I only get 100 items mapped to my ListBox.
Is this how the ListBox is designed for?
View 3 Replies
Dec 20, 2010
I wonder if there is a simple way to insert a new ListItem between 2 existing items of a dropdownlist?
View 3 Replies
May 15, 2010
I want give some space between the items of the dropdownlist. is it possible?
ddl:
item1
item2
item3
View 3 Replies
Mar 14, 2013
I have 2 table in data base
1-HOuse_info Table
2-House_p Table
in House_p table save users Product information and in House_info table save Users Information
In both Tables is column that name is BehcodeN
I want if users in BehcodeN save this text='free' 'they can't insert product morethan 2 number and if they want insert their third product It show error that You can't insert morethan 2 product below are my code
In Product.aspx page I have button that when users click on it they can insert their product
protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
{
string data = Server.UrlDecode(Request.QueryString["BehCode"]);
string price = RadioButton2.Checked ? TextBox1.Text : "null";
SqlCommand _cmd = new SqlCommand("insertproduct3", _cn);
[Code] ....
and SP
USE [behtop]
GO
/****** Object: StoredProcedure [dbo].[insertproduct3] Script Date: 03/14/2013 17:42:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[insertproduct3]
[Code] ....
ok here I can insert 2 product succesfully. but when I want insert third produt it makes below error instead of showing error message
Server Error in '/behtop website' Application.
Object cannot be cast from DBNull to other types.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Object cannot be cast from DBNull to other types.Source Error:
Line 805: _cmd.Parameters.AddWithValue("@behcode", data);
Line 806: _cmd.Parameters.AddWithValue("@id", Convert.ToInt32(ViewState["Id"]));
Line 807: int ID = Convert.ToInt32(_cmd.ExecuteScalar()); Line 808: if (ID > 0)
Line 809: {
why this happen?
View 1 Replies
Jan 4, 2010
I have a dropdownlist, which dynamically populate data from SQL Server and i wanna manually insert two items on top of the DDL after data binding. So, the DDL would has data something like this:
Select Branch (manually insert)
ALL (manually insert)
AIR
AMP
ABG
...
I tried to achieve it by using code below:
ddlBranch.Items.Insert(0, "Select Branch")
ddlBranch.Items(0).Value = CMM.sExcVal1
ddlBranch.Items.Insert(1, "ALL")
ddlBranch.Items(1).Value = "ALL"
but it comes out giving me the data like this:
Select Branch (manually insert)
ALL (manually insert)
('AIR' branch should be here but it's gone)
AMP
ABG
...
After manually insert the 'ALL' item into the DDL, the 'AIR' is gone which is already replaced by the 'ALL'. How can i remain all the data from server and at the same time i can manually insert two items?
View 3 Replies
Nov 29, 2010
what I am trying to do is: insert multiple selected items from CheckBoxList into DB
I tried using (foreach) as:
foreach (ListItem item in bookingid.Items)
{
if (item.Selected == true)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString))
{
con.Open();
SqlCommand cmd2 = new SqlCommand("") }}}
But it only adds the first selected item .. What Should i do ?
View 7 Replies
Feb 9, 2010
I am building a web site, it's used to manage the data in SQL server so the another web site(connect to the same SQL database) can receive the new infoSo far I've build 2 parts, one manages the news system, the another manages the album system, news manage system work perfect, when I update, add or delete news form the web site (using sqldatasource, INSERT, DELETE and UPDATE command), the data inside SQL changes as well.
View 2 Replies
Feb 19, 2010
I have Data table Populated from database with Column Month which contains values .
and i have an other Array list which contains the Months from 1 to 12.
Now i have to insert the missing months into Data table from Arraylist.
how i do that because i have to shown the 12 months on report .
View 4 Replies
May 8, 2010
I have two ListBoxes. I can move items from one list box to the other. I have an Insertcommand for inserting added values from the "ActivePrograms" list box to a db.
my problem is that it inserts only one item when sometimes the user added multiple items.
how do I insert all existing items from "ActivePrograms" list box?:
second issue: how do I make sure the insert command go through the list of items in the listbox and makes sure these rows does mot already exsited in the db? in other words insert only NEW values for that 'Id' value
[Code]....
View 8 Replies