Web Forms :: How To Insert Into DB Through Checkbox List
May 6, 2010I am using this for inserting into database through Checkbox list, but the problem is this it store first checked value in all the field in database.
[code]....
I am using this for inserting into database through Checkbox list, but the problem is this it store first checked value in all the field in database.
[code]....
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();
}
how to compare to checkbox list and show selected in first checkbox list
[Code]....
I am absoluetly confused. My web app has a checkbox list that my code is looking to see if the user checked it. Like I said, very simple stuff... Here's the code:
If (chkLaunch.Items(1).Selected) Then
Launch = 1
End If
The odd thing is that when it gets to this bit of code it just moves right past it like it wasn't checked. The same thing happens when I use a single checkbox (rather than a checkbox list). I've tried a bunch of different ways to make the code work but I'm left to the conclusion that I'm just not telling it to do this correctly. Either that or my project is messed up somehow.I say that my project is messed up because when I add an object to the page in Design mode, it doesn't write the source code. So when I save and close, all the modifications are mysteriously gone. This happens on multiple PC's...So, is the checkbox problem just me not doing something correctly or is my web project messed up?
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
How can i generate dropdown lists based on what has been selected in the checckbox list. Below is an example of what i need. if the user selects the options day, lotID and waferID, then 3 cascading dropdown lists should be displayed. And then a gridview displays data based on what has been chosen in the dropdown lists.
Day
LotID
SlotID
WaferID
VendorID
ToolID
LocationDetected
ProcessStep
Stage
Precipe
WaferStartMaterial
WaferStartVendor
WaferStartLot
WaferDiameterCOA
WaferMapTitle
BreakPoint
BreakpointSide
BreakpointMeasurement
I am at my wits end (again).
(reservation system, guest signs up and at the same time checks checkboxes to indicate their wishes)
[Code]....
[Code]....
[Code]....
I want to validate checkbox list, i am using this strategy which is mention in this lik given below
http://www.4guysfromrolla.com/webtech/tips/t040302-1.shtml
but i am using c#, and here they use script language ="vb" . so anyone tell me , How can I validate checkbox list using c#
I have a checkbox list , a textbox and a search button.
When I click search the data should populate into the checkbox list by using the textbox data as the parameter and I am using a BLL for it.
I have 6 states in my checkbox list and it may have 2 or 3 checked values.
If
dt4.Rows.Count > 0 Then
CheckBoxList1.DataSource = dt4
CheckBoxList1.DataTextField = "MI,IL,IA,WI,IN,OH" 'CheckBoxList1.Items(4).Selected = True
CheckBoxList1.DataBind()
I have a CheckBoxList (CBL) control inside a gridview. The CBL viewstate is enabled and I populate the CBL items from a session variable with the following code
[Code].....
How can I maintain (save) the user CBL selection while postback ?
Is there an easy way to clear all the selected items of a checkbox list control? When a user has selected multiple items?
View 2 RepliesIm creating a checkbox dynamically like so:
[Code]....
How can I add an onclick attribute to a particular list item?
I am trying to use linq to unselect the last selection if the user exceeds a particular selection. Assume you have a max set to 2. Now once the user reaches that I would like to uncheck the last one the user selected after this. I wrote something like this -
[Code]....
[Code]....
Replace checkbox list with image?
View 4 RepliesI have Checkbox list from database and selection list also from database . i can fill check boxlist from db in below . i have one datatable for selection items .i want that values to be selected in this checklist.
dt pagelist have 1 to 10
dt checklist have 1,3,5,7
DataTable dt = obj.checklist();
public void pagelist() {
DataTable pl = obj.pagelist();
foreach (DataRow row in pl.Rows) {
ListItem item = new ListItem();
item.Text = row["Previlage_pageName"].ToString();
item.Value = row["Previliges_ID"].ToString();
CHpagelist.Items.Add(item);
}
}
I'm adding a new checkbox list with list items.Is it possible that each list item will be a LinkButton with is own event Handler? Note that i want to add the items on server side dynamically.
View 1 Repliesi have a form with several checkboxes....i want to insert the selected checkbox values in to a single column in the sql database..
View 4 RepliesI would like to find a way of running custom validation on a checkbox list. The reason why is because they were a radiobutton list. Then our client decided they wanted to be able to uncheck them (without a clear button) so in the end I had to change them to checkbox lists and make them mutually exclusive. On some of them, one must be selected and I downloaded this: [URL] to set them as required - worked nicely. Perhaps there's a way of building on this further to create some sort of custom checkbox validation. why I need this custom validation is because when the built form checkbox list = flat or maisonette then floor level is then required.
View 3 RepliesI have a checkboxlist that gets all all the items from a look up table. The user is going to go to the list, check certail items and insert the checkboxid, the value (0 or 1), and the userid into a table valued paramater using a stored procedure. I have the user defined table type created but thats about it. Any body out there have any hints.
View 4 Replieshow to check the last unchecked item in checkbox list (asp.net 2.0).bcaz i googled for the past two days.I got some examples but all of them were based on LINQ,i need the same in asp.net 2.0
View 2 Repliesnow i am facing the problem to validate the checkboxlist is displaying dynamically, acutally at my present page i am doing the checkboxlist which is controled by another check box for the checkboxlist items for select and deselect, now i need to handle the validation for this checkboxlist for null value
[Code]....
been trying long time now to style the width of columns of a checkbox list, trying to group text by similar lengths, something like this:
small width [] wider width here [] widest width of all here []
small wid [] wider width h [] widest width of all h []
small widt [] wider width her [] widest width of all her [] (of course the checkboxes line up in the actual form)
so smaller length texts are not too far away from their checkbox, the checkboxlist control seems to have an iron grip on those col widths
I have a gridview object to which I added
<asp:TemplateField >
<ItemTemplate>
<asp:CheckBox ID="chkCopy"
OnCheckedChanged="chkStatus_OnCheckedChanged"
runat="server" />
</ItemTemplate>
</asp:TemplateField>
The page count is set to 10, when the user checks the checkbox(es), I will need to insert those records in a table. How will I know which row was selected? I found an example (untried) that is designed to loop through and insert the necessary records; but it does not address inserting records based on selecting rows via a checkbox. How do I put everything together.
// open connection
mySqlConnection.Open();
//enumerate the items in the list
foreach (SPListItem curItem in curItems)
{
string sql = "INSERT INTO ImportNotifications";
sql += "
(SharepointID,Title,WorkOrderNumber,Status,Department,ClientName,WorkOrderDueDate,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,Late,LateRe
view,TrueLate,Body)";
sql += " VALUES
(@ID,@Title,@WorkOrderNum,@Status,@Department,@ClientName,@WorkOrderDue,@Created,@Author,@Modified,@Editor,@Late,@LateReview,@TrueLate,@Bod
y)";
mySqlCommand.CommandText = sql;
mySqlCommand.Parameters.Clear();
mySqlCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.Float)).Value = curItem["ID"];
mySqlCommand.Parameters.Add(new SqlParameter("@Title", SqlDbType.NVarChar, 200)).Value =
curItem["Title"].ToString();
mySqlCommand.Parameters.Add(new SqlParameter("@WorkOrderNum", SqlDbType.NVarChar, 50)).Value =
curItem["Work_x0020_Order_x0020_Number"].ToString();
mySqlCommand.Parameters.Add(new SqlParameter("@Status", SqlDbType.NVarChar, 50)).Value =
curItem["Status"].ToString();
mySqlCommand.Parameters.Add(new SqlParameter("@Department", SqlDbType.NVarChar, 100)).Value =
curItem["Department"].ToString();
mySqlCommand.Parameters.Add(new SqlParameter("@ClientName", SqlDbType.NVarChar, 255)).Value =
curItem["Client_x0020_Name"].ToString();
mySqlCommand.Parameters.Add(new SqlParameter("@WorkOrderDue", SqlDbType.DateTime)).Value =
curItem["Work_x0020_Order_x0020_Due_x0020"];
mySqlCommand.Parameters.Add(new SqlParameter("@Created", SqlDbType.DateTime)).Value = curItem["Created"];
mySqlCommand.Parameters.Add(new SqlParameter("@Author", SqlDbType.NVarChar, 50)).Value =
curItem["Author"].ToString();
mySqlCommand.Parameters.Add(new SqlParameter("@Modified", SqlDbType.DateTime)).Value = curItem["Modified"];
mySqlCommand.Parameters.Add(new SqlParameter("@Editor", SqlDbType.NVarChar, 50)).Value = curItem["Editor"];
mySqlCommand.Parameters.Add(new SqlParameter("@Late", SqlDbType.NVarChar, 50)).Value = curItem["Late"];
mySqlCommand.Parameters.Add(new SqlParameter("@LateReview", SqlDbType.NVarChar, 50)).Value =
curItem["Late_x0020_Review"];
mySqlCommand.Parameters.Add(new SqlParameter("@TrueLate", SqlDbType.NVarChar, 50)).Value = curItem["TrueLate"];
mySqlCommand.Parameters.Add(new SqlParameter("@Body", SqlDbType.NVarChar, -1)).Value =
curItem["Body"].ToString();
// execute the command
mySqlCommand.ExecuteNonQuery();
}
// close the connection
mySqlConnection.Close();
i have checkboxlist & gridview, in which i want to make multi selection using checkbox, so when i click on checkbox the data will filter according to selected check box and appear in grid.
View 1 Replies[URL] i am trying to display one check box that would perform 'selectall/deselect all' . As I have data paging, I assume I do not have the id's of page 2 yet. how would one go about implementing this.
View 1 Replies