C# nder、事件参数(e) { SqlConnection=newsqlconnection(“数据源=192.168.0.65;初始目录=TestDataBase;持久安全信息=True;用户ID=sa;密码=mushko”); 使用(连接) { //connection.Open(); SqlCommand insert=new SqlCommand(“插入OOPR(CardCode、CardName、OpprId、CprCode、MaxSumLoc)值(@TextBox1、@TextBox2、@TextBox3、@TextBox4、@TextBox5)”,连接);/(“+TextBox1.Text+”、“+TextBox2.Text+”、“+DropDownList1.Text+”、“+TextBox4.Text+”),连接); insert.Parameters.AddWithValue(“@TextBox1”,TextBox1.Text); insert.Parameters.AddWithValue(“@TextBox2”,TextBox2.Text); insert.Parameters.AddWithValue(“@TextBox3”,TextBox3.Text); insert.Parameters.AddWithValue(“@TextBox4”,TextBox4.Text); insert.Parameters.AddWithValue(“@TextBox5”,TextBox4.Text); connection.Open(); //connection.CommandType=CommandType.Text; //connection.commandType=commandType.Text; //试一试 // { insert.ExecuteNonQuery(); connection.Close(); // } //抓住 //{ //TextBox5.Text=“在数据库上保存时出错”; //connection.Close(); //} //TextBox1.Text=“”; //TextBox2.Text=“”; //TextBox3.Text=“”; //TextBox4.Text=“”; } } 受保护的无效按钮2\u单击(对象发送者,事件参数e) { this.ClientScript.RegisterClientScriptBlock(this.GetType(),“Close”,“window.Close()”,true); //这个。关闭(); } 受保护的void DropDownList2\u SelectedIndexChanged(对象发送方,事件参数e) { } } }
这是apsx代码C# nder、事件参数(e) { SqlConnection=newsqlconnection(“数据源=192.168.0.65;初始目录=TestDataBase;持久安全信息=True;用户ID=sa;密码=mushko”); 使用(连接) { //connection.Open(); SqlCommand insert=new SqlCommand(“插入OOPR(CardCode、CardName、OpprId、CprCode、MaxSumLoc)值(@TextBox1、@TextBox2、@TextBox3、@TextBox4、@TextBox5)”,连接);/(“+TextBox1.Text+”、“+TextBox2.Text+”、“+DropDownList1.Text+”、“+TextBox4.Text+”),连接); insert.Parameters.AddWithValue(“@TextBox1”,TextBox1.Text); insert.Parameters.AddWithValue(“@TextBox2”,TextBox2.Text); insert.Parameters.AddWithValue(“@TextBox3”,TextBox3.Text); insert.Parameters.AddWithValue(“@TextBox4”,TextBox4.Text); insert.Parameters.AddWithValue(“@TextBox5”,TextBox4.Text); connection.Open(); //connection.CommandType=CommandType.Text; //connection.commandType=commandType.Text; //试一试 // { insert.ExecuteNonQuery(); connection.Close(); // } //抓住 //{ //TextBox5.Text=“在数据库上保存时出错”; //connection.Close(); //} //TextBox1.Text=“”; //TextBox2.Text=“”; //TextBox3.Text=“”; //TextBox4.Text=“”; } } 受保护的无效按钮2\u单击(对象发送者,事件参数e) { this.ClientScript.RegisterClientScriptBlock(this.GetType(),“Close”,“window.Close()”,true); //这个。关闭(); } 受保护的void DropDownList2\u SelectedIndexChanged(对象发送方,事件参数e) { } } },c#,jquery,asp.net,C#,Jquery,Asp.net,这是apsx代码 <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="StackOver._Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="H
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="StackOver._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET!
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
</h2>
<br />
<p>
Business Partner Code :
<asp:TextBox ID="TextBox1" runat="server" Width="192px" ></asp:TextBox>
</p>
<p>
Business Partner Name :
<asp:TextBox ID="TextBox2" runat="server" Width="192px" ></asp:TextBox>
</p>
<p>
Opportunity No. :
<asp:TextBox ID="TextBox3" runat="server" Width="196px" ></asp:TextBox>
</p>
<p>
Contact Person Name :
<asp:TextBox ID="TextBox4" runat="server" Width="196px" ></asp:TextBox>
</p>
<p>
Total Amount Invoiced:
<asp:TextBox ID="TextBox5" runat="server" Width="193px" ></asp:TextBox>
</p>
<p>
Business partner Territory:
<asp:TextBox ID="TextBox6" runat="server" Width="174px" ></asp:TextBox>
</p>
<p>
Sales Employee:
<asp:TextBox ID="TextBox7" runat="server" Width="235px" ></asp:TextBox>
</p>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Add"
Width="140px" />
<asp:Button ID="Button2" runat="server" Text="Cancel" Width="149px"
onclick="Button2_Click" />
</p>
</asp:Content>
欢迎使用ASP.NET!
业务伙伴代码:
业务伙伴名称:
机会编号:
联系人姓名:
发票总金额:
业务伙伴地区:
销售人员:
将筛选后的客户放入数据表(dt)中,并按如下方式填写:
DropDownList2.DataTextField = "CustomerName";
DropDownList2.DataValueField = "CustomerID";
DropDownList2.DataSource = dt;
DropDownList2.DataBind();
一旦list1触发selectedindexchanged事件,list2将更改其值
protected void LoadOptions()
{
DataTable CardCode = new DataTable();
string id, name, newName, name2;
SqlConnection connection = new SqlConnection("Data Source=adfsadf;Initial Catalog=TestDatabse;Persist Security Info=True;User ID=asd;Password=asdf");
using (connection)
{
SqlDataAdapter adapter = new SqlDataAdapter("SELECT T1.CardCode , T1.CardName, T2.OpprId,T1.CntctPrsn, T2.CprCode,T2.MaxSumLoc FROM OCRD T1 left join OOPR T2 on T1.CardCode=T2.CardCode" , connection);
adapter.Fill(CardCode);
if (CardCode.Rows.Count > 0)
{
for (int i = 0; i < CardCode.Rows.Count; i++)
{
id = CardCode.Rows[i]["CardCode"].ToString();
name = CardCode.Rows[i]["CardName"].ToString();
newName = id + " ---- " + name;
//name2 = id;
DropDownList1.Items.Add(new ListItem(newName, id));
//*******HERE*****//
DropDownList2.DataSource = CardCode;
DropDownList2.DataBind();
DropDownList2.DataValueField = "CardCode";
DropDownList2.DataTextField = "CntctPrsn";
//*******HERE*****//
}
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string selected = DropDownList1.SelectedItem.Value;
SqlConnection connection = new SqlConnection("Data Source=mydtasrc;Initial Catalog=TestDatabs;Persist Security Info=True;User ID=asf;Password=asdfgh");
using (connection)
{
// SqlCommand theCommand = new SqlCommand("SELECT CardCode, CardName, OpprId, CprCode,MaxSumLoc FROM OOPR WHERE CardCode = @CardCode", connection);
SqlCommand theCommand = new SqlCommand("SELECT T1.CardCode , T1.CardName, T2.OpprId, T1.CntctPrsn,T2.CprCode FROM OCRD T1 left join OOPR T2 on T1.CardCode=T2.CardCode where T1.CardCode=@CardCode", connection);
connection.Open();
theCommand.Parameters.AddWithValue("@CardCode", selected);
theCommand.CommandType = CommandType.Text;
SqlDataReader theReader = theCommand.ExecuteReader();
if (theReader.Read())
{
this.TextBox1.Text = theReader["CardCode"].ToString();
this.TextBox2.Text = theReader["CardName"].ToString();
this.TextBox5.Text = theReader["CprCode"].ToString();
this.TextBox3.Text = theReader["OpprId"].ToString();
//*******AND HERE*****//
this.DropDownList2.SelectedValue = selected;
//*******AND HERE*****//
}
connection.Close();
}
}
protectedvoid LoadOptions()
{
DataTable CardCode=新DataTable();
字符串id、名称、新名称、名称2;
SqlConnection=newsqlconnection(“数据源=adfsadf;初始目录=testdatabase;持久安全信息=True;用户ID=asd;密码=asdf”);
使用(连接)
{
SqlDataAdapter=新的SqlDataAdapter(“选择T1.CardCode、T1.CardName、T2.Oppred、T1.CNTCTPRN、T2.CprCode、T2.MaxSumLoc,从OCRD T1左连接到T1.CardCode=T2.CardCode上的OOPR T2”,连接);
适配器。填充(CardCode);
如果(CardCode.Rows.Count>0)
{
对于(int i=0;i
您需要在Google上查找级联下拉列表。将两个下拉列表的AutoPostBack属性都设置为true。感谢您的回复,但此代码无法正常工作,因为我需要相同的列表
protected void LoadOptions()
{
DataTable CardCode = new DataTable();
string id, name, newName, name2;
SqlConnection connection = new SqlConnection("Data Source=adfsadf;Initial Catalog=TestDatabse;Persist Security Info=True;User ID=asd;Password=asdf");
using (connection)
{
SqlDataAdapter adapter = new SqlDataAdapter("SELECT T1.CardCode , T1.CardName, T2.OpprId,T1.CntctPrsn, T2.CprCode,T2.MaxSumLoc FROM OCRD T1 left join OOPR T2 on T1.CardCode=T2.CardCode" , connection);
adapter.Fill(CardCode);
if (CardCode.Rows.Count > 0)
{
for (int i = 0; i < CardCode.Rows.Count; i++)
{
id = CardCode.Rows[i]["CardCode"].ToString();
name = CardCode.Rows[i]["CardName"].ToString();
newName = id + " ---- " + name;
//name2 = id;
DropDownList1.Items.Add(new ListItem(newName, id));
//*******HERE*****//
DropDownList2.DataSource = CardCode;
DropDownList2.DataBind();
DropDownList2.DataValueField = "CardCode";
DropDownList2.DataTextField = "CntctPrsn";
//*******HERE*****//
}
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string selected = DropDownList1.SelectedItem.Value;
SqlConnection connection = new SqlConnection("Data Source=mydtasrc;Initial Catalog=TestDatabs;Persist Security Info=True;User ID=asf;Password=asdfgh");
using (connection)
{
// SqlCommand theCommand = new SqlCommand("SELECT CardCode, CardName, OpprId, CprCode,MaxSumLoc FROM OOPR WHERE CardCode = @CardCode", connection);
SqlCommand theCommand = new SqlCommand("SELECT T1.CardCode , T1.CardName, T2.OpprId, T1.CntctPrsn,T2.CprCode FROM OCRD T1 left join OOPR T2 on T1.CardCode=T2.CardCode where T1.CardCode=@CardCode", connection);
connection.Open();
theCommand.Parameters.AddWithValue("@CardCode", selected);
theCommand.CommandType = CommandType.Text;
SqlDataReader theReader = theCommand.ExecuteReader();
if (theReader.Read())
{
this.TextBox1.Text = theReader["CardCode"].ToString();
this.TextBox2.Text = theReader["CardName"].ToString();
this.TextBox5.Text = theReader["CprCode"].ToString();
this.TextBox3.Text = theReader["OpprId"].ToString();
//*******AND HERE*****//
this.DropDownList2.SelectedValue = selected;
//*******AND HERE*****//
}
connection.Close();
}
}