Data Controls :: Insert Checkbox Value Into Database?
Aug 23, 2013
I have 3 Checkbox in my page and insertbutton
1-ChkPeyment
2-ChkFilter
3-ChkLaw
and below is table in database
Id Name Date Behcode reason
1 Sara 2012 1111 Payment
2 Jack 2013 2222 Filter
I want if users checked ChFilter it insert "Filter" in reason column if they checked ChkLaw it insert "Law" in database and if they checked ChkLaw AND ChkLaw (both) it insert "Other" it insert "Other" in reason column
below is .cs
string other = ChOther.Checked ? "1" : "";
string Filter = ChFilter.Checked ? "1" : "";
string data = Request.QueryString["id"];
I have grid view in ASP.Net 3.5. I need to add multiple blank rows in a gridview and then have to save them in database. How can I do that in most simplest way?
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(); }
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.
i have two sqldatasource controls. one i use to display data in textbox's ,filter'd by a select parameter in page behind code. Once checked, i want to copy this data to the other datasource ,by selecting checkbox.Then display this data in detailsview control.
At present the two datasource controls declared , render data to the page simultaneously during pageload. I want to first check data in textbox's from first source, before second datasource is rendered to screen. note, both are filtered by a page variable. i wish to leave the textbox datasource control in situ, as other controls and code depend on it.The other detailsview datasource is my problem?
how to set checkbox status Checked in gridview when in detabase column "type = Y" and when "type =N" that time checked is uncheked on rowdata bount of gridview
I have been stuck on this for a while and I can't seem to get it to work despite looking for answers in books and all over the web, so I hope perhaps you all can help me figure this out...
Here's what I'm trying to do....
I have some information in a simple product database displaying in a gridview table. One of the columns is a row of checkboxes indicating whether the item has been discontinued or not. When the row gets updated, it needs to update the checkbox value in the database.
1. It needs to be disabled until the row is getting edited.
2. Send the string value of 0 or 1 to the database when the row is updated.
Here's the code for the sql datasource and the gridview part in question...
I have a field "Active" which can contain either 1 or 0. In the aspx form, I am displaying it in a checkbox in gridview. If the database value is 1, I should have the checkbox as checked, otherwise it should be unchecked. How can this be done.
I am posting this in the webforms section as I don't think I was clear on my last post. I am trying toinsert a gridview checkbox value to a database when I click the submit button. I have looked at dozens of examples but can't seem to put it together and I know this must be pretty simple.
Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles FormView1.ItemUpdating Dim IsPresCheck As CheckBox = CType(FormView1.FindControl("IsPrestigeChkBx"), CheckBox) If IsPresCheck.Checked = "True" Then SqlDataSource1.SelectParameters.Add("IsPrestige", System.TypeCode.Int32, 1.ToString) Else SqlDataSource1.SelectParameters.Add("IsPrestige", System.TypeCode.Int32, 0.ToString) End If
but for some reason it's not seeing the parameter and returning an error
I am trying to input some data into the database and it just won't make INSERT. Before, I am checking for duplicate entry and then I am trying to insert the data. Here is the code:
In the end I have the warning that con.Close() - unreacheable code detected.
i have code to update multiple rows in a gridview. What I want is that if the row value is = 1 in the database then the row is checked otherwise it's not. I've put some pseudo code in below to illustrate what I want to achieve.
My problem is this "I have all the tools, VS 2005, 2008, 2010. I have every book, I have SQL server 2005 and 2008" I have all the tools, but I do not know what tool or technology to use when starting out learning all this. I juat do not know what book teaches what I need to do for something like below.
Here is my question:
I created an .ASPX webform that is to "Submit" to a SQL 2005 database. I gave this form to my DBA, and he has made up a Data Model. Now I have to figure out how to write the ASP.NET code so it will submit to the DB. My first issue is not knowing this:
1. "How do I loop through my CheckBox List", and then insert the values checked into a "Database Table" (Each Checkbox value MUST be a seperate row in the table, the DBA does not want a seperate column for each checkbox value)
2. The database is using stored procedures
3. My third issue is this: "I do not know "where" to put the "code". If you do resond to this,
Summary: I just need shown the code on how to "loop through" the CheckBox List on my form, and insert those values into a database table as seperate rows.
Here I want to assign the above database work to my team members. When I check the above check box and press assign button ,it shows in another page means the gridview selected row shows in another grid in another page .
And once i check any check box and assign , automatically the checked row vanished from my grid view.
I have a gridview inside which there are 4-5 checkboxes. In that gridview, I have 10 rows too. So, Now what i want is.
IF I check, 2 checkboxes and don't check remaining checkboxes. how to save the value of the checked checkboxes value as Y and unchecked checkboxes value as N into the database.
i got my checkbox control in each row.actually my problem is i bound checkbox in a gridviw and i need those checkbox are checkd if database values are match.i do it like below
[Code]....
but problem is only one checkbox is checked.in page_Load i bind gridviw in ROwDatabound event i check Duecode in another table.so i need only matching checkbox should be checked.
currently I am doing a web application project using 3-tier formating to do out the project. In the grid view is displayed with data retrieved from the database and at the footer there is a row of empty fields for the user to insert records into database and when user clicks on Add New, a new row of empty fields will be populated below.
The database.cs and stored procedure is used to stored the data into the database.
[Code]....
This is the stored procedure code:
[Code]....
I am not sure of how to code out for the business logic?
I code this in business logic but its wrong as the error states the Insert method could not be found:
I m uploading a text file. I want to read that text file line by line and I want to save that data into database if there are no errors in that text file. I have 5 different columns in database and I want to take those 5 columns data in the text file and insert into respective columns.
For this, which is the best way to do. Can we read and insert data into respective fields in no time.