asp.net - how to insert multiple checkbox list values into database in single column using c# -


How do I use a selected checkbox to select from the column I selected, I would call it multiple checkboxes in the same column In this list, I use several methods, 3 days without success

  Private Zero 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) {checkbox list 1. Repetition column = 4; // Set the number of columns in the checkbox CheckBoxList1.DataSource = dt; Checkbox label 1.datextfold = "name"; Items displayed in the list item checkbox checkboxlist 1. Data value = "name"; // The ID of the items shows the checkbox data Bank (); // Set the selected item in the database based on value in the database, to do so, to rewrite each item in the list (int i = 0; i & lt; dt.rows.Count; i ++) {If (! String.IsNullOrEmpty (dt.rows [i] ["isSelected"]. ToString ())) {checkbox list 1. ITEMS [i]. Selected = Convert.Toboolean (dt.Rows [i] ["IsSelected"]); }}}} Hold (System.Data.SqlClient.SqlException pre) {string msg = "get error:"; Msg = = ex.Message; Throw a new exception (msg); } Finally {connection.Close (); }} Private Zero update (name of string, boole is selected) {SqlConnection connection = New SqlConnection (GetConnectionString ()); SqlCommand CMD; String sqlStatement = string.Empty; Try {connection.Open (); SqlStatement = "upstate handmade SET IsSelected = @Iselected WHERE name = @BizName"; CMD = new SQL Commands (escalation, connection); Cmd.Parameters.AddWithValue ("@Name", name); Cmd.Parameters.AddWithValue ("@IsSelected", selected); Cmd.CommandType = CommandType.Text; Cmd.ExecuteNonQuery (); } Hold (System.Data.SqlClient.SqlException pre) {string msg = "Insert / update error"; Msg = = ex.Message; Throw a new exception (msg); } Finally {connection.Close (); }} Secure Zero Page_load (Object Sender, EventAgds E) {if (! Page. ISPostBack) {BindCheckBoxList (); }} Secure Zero Button 1_Click (Object Sender, EventArgs e) {string str = string.Empty; (IntitI = 0; I & lt; Checkbox list 1.Items.Count; i ++) {If (checkbox list 1. item is selected) {str = checkbox list 1. Item [i] Text; Updates (Str, checkbox list 1. items. [I] selected); }} // BindCheckBoxList () to re-order the list to retain the selected items on postback; }  

Well, if you are going to do that, then the best way would be to To sum up in a bit-wise composite, maybe this way:

  int value = 0; // bit or long, based on the number of bits bit bitDegree = 1; // (or I. Ostring ()) & amp; Amp; Convert ToBoolean (dt.Rows [i] ["IsSelected"])) {value + = bitDegree; } Bitdigit * = 2; }  

However, if you can, they would be the best practice to use multiple bit columns in your database instead of combining them.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -