<%@ Page Language="C#" AutoEventWireup="true" CodeFile="listbox.aspx.cs" Inherits="listbox" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="MySql.Data.MySqlClient" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <fieldset style="width: 300px"> <legend>Do you have </legend> <asp:CheckBoxList ID="CBLID" runat="server"></asp:CheckBoxList> <asp:Button ID="BtnSubmit" runat="server" Text="Submit" onclick="BtnSubmit_Click" /><br /> </fieldset> </div> </form> </body> </html>
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using MySql.Data.MySqlClient; public partial class listbox : System.Web.UI.Page { MySqlConnection objConn = new MySqlConnection(); MySqlCommand objCmd = new MySqlCommand(); MySqlDataReader dtReader; String strConnString, strSQL, selSql; public void conn() { strConnString = "Server=test; User Id=test; Password=test; Database=test; Pooling=false"; objConn = new MySqlConnection(strConnString); objConn.Open(); } protected void Page_Load(object sender, EventArgs e) { conn(); String prSQL; prSQL = "SELECT * FROM probrefqp"; objCmd = new MySqlCommand(prSQL, objConn); dtReader = objCmd.ExecuteReader(); CBLID.DataValueField = "problem_description"; CBLID.DataTextField = "problem_description"; CBLID.DataSource = dtReader; CBLID.DataBind(); //CBLID.Items[0].Selected = true; dtReader.Close(); } protected void BtnSubmit_Click(object sender, EventArgs e) { String str = ""; String InsSQL; for (int i = 0; i <= CBLID.Items.Count - 1; i++) { if (CBLID.Items[i].Selected = true) { if (str == "") { str = CBLID.Items[i].Value.ToString(); } else { str += "," + CBLID.Items[i].Value.ToString(); } } } InsSQL = "Insert into custqp(qp_probref) values('" + str + "')"; objCmd = new MySql.Data.MySqlClient.MySqlCommand(); objCmd.Connection = objConn; objCmd.CommandType = CommandType.Text; objCmd.CommandText = InsSQL; objCmd.ExecuteNonQuery(); Response.Write("'" + str + "'"); CBLID.SelectedIndex = -1; objCmd = null; objConn.Close(); objConn = null; } }
for (int i = 0; i <= CBLID.Items.Count - 1; i++) { if (CBLID.Items[i].Selected = true) { if (str == "") { str = CBLID.Items[i].Value.ToString(); } else { str += "," + CBLID.Items[i].Value.ToString(); } } }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง