你可以通过一个中间来完成,也可以直接绑定:以下是一个二级联动的例子,用callback 页面不刷新,不晃动的: protected string strCallBack; public void RaiseCallbackEvent(string Areument)
{
int id = Convert.ToInt32(Areument);
type2.Items.Clear();
BindDropDownListType2(id); TextWriter textwriter = new StringWriter();
HtmlTextWriter htmlwriter = new HtmlTextWriter(textwriter);
type2.RenderControl(htmlwriter);
strCallBack = htmlwriter.InnerWriter.ToString();
}
public string GetCallbackResult()
{
return strCallBack;
}
protected void BindDropDownListType1()
{
SqlConnection con = new SqlConnection("SERVER=localhost;DATABASE=BBS;Integrated Security=SSPI;Connect Timeout=30;");
con.Open(); DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from Bbs_Type", con);
da.Fill(ds); con.Close(); type1.DataSource = ds.Tables[0].DefaultView;
type1.DataTextField = "Type_Name";
type1.DataValueField = "Type_ID";
type1.DataBind(); }
protected void Page_Load(object sender, EventArgs e)
{
BindDropDownListType1();
type1.Attributes.Add("onchange", "Call()");
//给下拉列表添加onchange事件
string script = Page.ClientScript.GetCallbackEventReference(this, "arg", "Recieve", "");
//"arg"为从客户端传过来的参数,与下一行的arg对应; Receive 为客户端接收服务器返回数据的处理函数
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Call", "function Call(){var arg=document.getElementById(\"type1\").value;" + script + "}", true);
}<script type="text/javascript">
function Recieve(html)
{
document.getElementById("span2").innerHTML = html;
//二级列表放在SPAN中。。
}
</script><body onload="Call()">
……
{
int id = Convert.ToInt32(Areument);
type2.Items.Clear();
BindDropDownListType2(id); TextWriter textwriter = new StringWriter();
HtmlTextWriter htmlwriter = new HtmlTextWriter(textwriter);
type2.RenderControl(htmlwriter);
strCallBack = htmlwriter.InnerWriter.ToString();
}
public string GetCallbackResult()
{
return strCallBack;
}
protected void BindDropDownListType1()
{
SqlConnection con = new SqlConnection("SERVER=localhost;DATABASE=BBS;Integrated Security=SSPI;Connect Timeout=30;");
con.Open(); DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from Bbs_Type", con);
da.Fill(ds); con.Close(); type1.DataSource = ds.Tables[0].DefaultView;
type1.DataTextField = "Type_Name";
type1.DataValueField = "Type_ID";
type1.DataBind(); }
protected void Page_Load(object sender, EventArgs e)
{
BindDropDownListType1();
type1.Attributes.Add("onchange", "Call()");
//给下拉列表添加onchange事件
string script = Page.ClientScript.GetCallbackEventReference(this, "arg", "Recieve", "");
//"arg"为从客户端传过来的参数,与下一行的arg对应; Receive 为客户端接收服务器返回数据的处理函数
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Call", "function Call(){var arg=document.getElementById(\"type1\").value;" + script + "}", true);
}<script type="text/javascript">
function Recieve(html)
{
document.getElementById("span2").innerHTML = html;
//二级列表放在SPAN中。。
}
</script><body onload="Call()">
……
我只是希望在TextBox中录入物料编号,点‘按钮’,按物料编号查询数据库,查询出的值到其它的TextBox中
前提是希望刷新本页。