select 控件的单击事件怎么做_html/css_WEB-ITnose
程序员文章站
2022-05-30 20:21:23
...
select
想要在点击的时候发给服务器一个参数要怎么做
单击事件已经做出来了 但是用这个运行服务器端的代码会导致服务器端的代码运行顺序发生问题 运行出来的程序不会报错,能运行 但功能有时候能实现有时候不能实现
这是完整的JS代码
接下来是完整的服务器端代码
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Xml;
using System.Xml.Serialization;
using System.Text;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "text/xml";
Response.Charset = "UTF-8";
string db = "Data Source=LENOVO-85DD1539;Initial Catalog=Emne;User ID=sa;Password=ehs123456";
string sql = "select * from Emne";
SqlConnection conn = new SqlConnection(db);
conn.Open();
SqlCommand comm = new SqlCommand(sql, conn);
SqlDataReader sdr = comm.ExecuteReader();
Class1 c = new Class1();
while (sdr.Read())
{
c.Id = Convert.ToInt32(sdr["Id"]);
c.Temperature = Convert.ToInt32(sdr["Temperature"]);
c.Humidity = Convert.ToInt32(sdr["Humidity"]);
c.Airquality = Convert.ToInt32(sdr["Airquality"]);
c.Fan = Convert.ToInt32(sdr["Fan"]);
c.Button1 = Convert.ToInt32(sdr["Button1"]);
c.Button2 = Convert.ToInt32(sdr["Button2"]);
c.Button3 = Convert.ToInt32(sdr["Button3"]);
c.Button4 = Convert.ToInt32(sdr["Button4"]);
c.Button5 = Convert.ToInt32(sdr["Button5"]);
c.Button6 = Convert.ToInt32(sdr["Button6"]);
}
XmlWriter writer = null;
try
{
XmlSerializer serializer = new XmlSerializer(c.GetType());
//string l = AppDomain.CurrentDomain.BaseDirectory;
//StreamWriter myWriter = new StreamWriter(l + "/myFileName.xml");
//mySerializer.Serialize(myWriter, c);
writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
serializer.Serialize(writer, c);
}
finally
{
if (writer != null)
{
writer.Close();
}
}
if (Request.QueryString["bu"] != null)
{
try
{
string id = Request.QueryString["bu"].ToString();
if (id.Equals("Button1"))
{
if (c.Button1 == 0)
{
sql = "update Emne set Button1=1 where Id=" + c.Id;
}
else
{
sql = "update Emne set Button1=0 where Id=" + c.Id;
}
conn.Close();
conn.Open();
comm = new SqlCommand(sql, conn);
comm.ExecuteReader();
conn.Close();
}
if (id.Equals("Button2"))
{
if (c.Button1 == 0)
{
sql = "update Emne set Button2=1 where Id=" + c.Id;
}
else
{
sql = "update Emne set Button2=0 where Id=" + c.Id;
}
conn.Close();
conn.Open();
comm = new SqlCommand(sql, conn);
comm.ExecuteReader();
conn.Close();
}
if (id.Equals("Button3"))
{
if (c.Button1 == 0)
{
sql = "update Emne set Button3=1 where Id=" + c.Id;
}
else
{
sql = "update Emne set Button3=0 where Id=" + c.Id;
}
conn.Close();
conn.Open();
comm = new SqlCommand(sql, conn);
comm.ExecuteReader();
conn.Close();
}
if (id.Equals("Button4"))
{
if (c.Button1 == 0)
{
sql = "update Emne set Button4=1 where Id=" + c.Id;
}
else
{
sql = "update Emne set Button4=0 where Id=" + c.Id;
}
conn.Close();
conn.Open();
comm = new SqlCommand(sql, conn);
comm.ExecuteReader();
conn.Close();
}
if (id.Equals("Button5"))
{
if (c.Button1 == 0)
{
sql = "update Emne set Button5=1 where Id=" + c.Id;
}
else
{
sql = "update Emne set Button5=0 where Id=" + c.Id;
}
conn.Close();
conn.Open();
comm = new SqlCommand(sql, conn);
comm.ExecuteReader();
conn.Close();
}
if (id.Equals("Button6"))
{
if (c.Button1 == 0)
{
sql = "update Emne set Button6=1 where Id=" + c.Id;
}
else
{
sql = "update Emne set Button6=0 where Id=" + c.Id;
}
conn.Close();
conn.Open();
comm = new SqlCommand(sql, conn);
comm.ExecuteReader();
conn.Close();
}
}
finally
{
}
}
}
}
求大神帮忙看一下BUG出在哪里
想要在点击的时候发给服务器一个参数要怎么做
回复讨论(解决方案)
用change事件不行吗 只有发生变化时才发送请求
用change事件不行吗 只有发生变化时才发送请求
请来点代码 菜鸟一只
不行 点击了毫无反应
用change事件不行吗 只有发生变化时才发送请求
看图片怎么感觉楼主用的不是select啊?select的change事件应该是可以的。代码能看看不?
这东西不是select的吧
这东西不是select的吧
是select是JQM上面的用了框架
看图片怎么感觉楼主用的不是select啊?select的change事件应该是可以的。代码能看看不?
这是控件的代码
单击事件已经做出来了 但是用这个运行服务器端的代码会导致服务器端的代码运行顺序发生问题 运行出来的程序不会报错,能运行 但功能有时候能实现有时候不能实现
这是完整的JS代码
接下来是完整的服务器端代码
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Xml;
using System.Xml.Serialization;
using System.Text;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "text/xml";
Response.Charset = "UTF-8";
string db = "Data Source=LENOVO-85DD1539;Initial Catalog=Emne;User ID=sa;Password=ehs123456";
string sql = "select * from Emne";
SqlConnection conn = new SqlConnection(db);
conn.Open();
SqlCommand comm = new SqlCommand(sql, conn);
SqlDataReader sdr = comm.ExecuteReader();
Class1 c = new Class1();
while (sdr.Read())
{
c.Id = Convert.ToInt32(sdr["Id"]);
c.Temperature = Convert.ToInt32(sdr["Temperature"]);
c.Humidity = Convert.ToInt32(sdr["Humidity"]);
c.Airquality = Convert.ToInt32(sdr["Airquality"]);
c.Fan = Convert.ToInt32(sdr["Fan"]);
c.Button1 = Convert.ToInt32(sdr["Button1"]);
c.Button2 = Convert.ToInt32(sdr["Button2"]);
c.Button3 = Convert.ToInt32(sdr["Button3"]);
c.Button4 = Convert.ToInt32(sdr["Button4"]);
c.Button5 = Convert.ToInt32(sdr["Button5"]);
c.Button6 = Convert.ToInt32(sdr["Button6"]);
}
XmlWriter writer = null;
try
{
XmlSerializer serializer = new XmlSerializer(c.GetType());
//string l = AppDomain.CurrentDomain.BaseDirectory;
//StreamWriter myWriter = new StreamWriter(l + "/myFileName.xml");
//mySerializer.Serialize(myWriter, c);
writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
serializer.Serialize(writer, c);
}
finally
{
if (writer != null)
{
writer.Close();
}
}
if (Request.QueryString["bu"] != null)
{
try
{
string id = Request.QueryString["bu"].ToString();
if (id.Equals("Button1"))
{
if (c.Button1 == 0)
{
sql = "update Emne set Button1=1 where Id=" + c.Id;
}
else
{
sql = "update Emne set Button1=0 where Id=" + c.Id;
}
conn.Close();
conn.Open();
comm = new SqlCommand(sql, conn);
comm.ExecuteReader();
conn.Close();
}
if (id.Equals("Button2"))
{
if (c.Button1 == 0)
{
sql = "update Emne set Button2=1 where Id=" + c.Id;
}
else
{
sql = "update Emne set Button2=0 where Id=" + c.Id;
}
conn.Close();
conn.Open();
comm = new SqlCommand(sql, conn);
comm.ExecuteReader();
conn.Close();
}
if (id.Equals("Button3"))
{
if (c.Button1 == 0)
{
sql = "update Emne set Button3=1 where Id=" + c.Id;
}
else
{
sql = "update Emne set Button3=0 where Id=" + c.Id;
}
conn.Close();
conn.Open();
comm = new SqlCommand(sql, conn);
comm.ExecuteReader();
conn.Close();
}
if (id.Equals("Button4"))
{
if (c.Button1 == 0)
{
sql = "update Emne set Button4=1 where Id=" + c.Id;
}
else
{
sql = "update Emne set Button4=0 where Id=" + c.Id;
}
conn.Close();
conn.Open();
comm = new SqlCommand(sql, conn);
comm.ExecuteReader();
conn.Close();
}
if (id.Equals("Button5"))
{
if (c.Button1 == 0)
{
sql = "update Emne set Button5=1 where Id=" + c.Id;
}
else
{
sql = "update Emne set Button5=0 where Id=" + c.Id;
}
conn.Close();
conn.Open();
comm = new SqlCommand(sql, conn);
comm.ExecuteReader();
conn.Close();
}
if (id.Equals("Button6"))
{
if (c.Button1 == 0)
{
sql = "update Emne set Button6=1 where Id=" + c.Id;
}
else
{
sql = "update Emne set Button6=0 where Id=" + c.Id;
}
conn.Close();
conn.Open();
comm = new SqlCommand(sql, conn);
comm.ExecuteReader();
conn.Close();
}
}
finally
{
}
}
}
}
求大神帮忙看一下BUG出在哪里