gridview的下拉列表问题 [英] dropdownlist problem with gridview
本文介绍了gridview的下拉列表问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我从下拉列表中选择模型并在文本框中写入模型,那么它在gridview中显示值但是当我从下拉列表中选择sn时它没有显示任何内容。请帮助我
if i select model from dropdownlist and write model in text box then it show value in gridview but when i select sn from dropdownlist it shows nothing.please help me
SqlConnection con;
con = new SqlConnection(connstring);
con.Open();
//string str = "SELECT * FROM ['ISB VAS Nodes$']";
if (DropDownList1.Text == "Model")
{
string str = "SELECT * FROM ['ISB VAS Nodes$'] where Model='" + TextBox2.Text + "'";
//city is the column name in table
SqlCommand cmd;
cmd = new SqlCommand(str, con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
//if city is in 0 index of table
GridView1.DataSource = dr;
GridView1.DataBind();
}
else
{
Response.Write("City does not exist");
}
dr.Close();
con.Close();
}
else if(DropDownList1.Text=="SN")
{
string str = "SELECT * FROM ['ISB VAS Nodes$'] where SN='" + TextBox2.Text + "'";
//city is the column name in table
SqlCommand cmd;
cmd = new SqlCommand(str, con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
//if city is in 0 index of table
GridView1.DataSource = dr;
GridView1.DataBind();
}
else
{
Response.Write("City does not exist");
}
dr.Close();
con.Close();
}
推荐答案
'];
if (DropDownList1.Text == Model)
{
string str = SELECT * FROM [' ISB VAS节点
']"; if (DropDownList1.Text == "Model") { string str = "SELECT * FROM ['ISB VAS Nodes
']其中Model =' + TextBox2.Text + ';
// city是表格中的列名
SqlCommand cmd;
cmd = new SqlCommand(str,con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
// 如果city在表的0索引中
GridView1.DataSou rce = dr;
GridView1.DataBind();
}
else
{
Response.Write( 城市不存在);
}
dr.Close();
con.Close();
}
else if (DropDownList1.Text == SN)
{
string str = SELECT * FROM ['ISB VAS Nodes
'] where Model='" + TextBox2.Text + "'"; //city is the column name in table SqlCommand cmd; cmd = new SqlCommand(str, con); SqlDataReader dr; dr = cmd.ExecuteReader(); if (dr.Read()) { //if city is in 0 index of table GridView1.DataSource = dr; GridView1.DataBind(); } else { Response.Write("City does not exist"); } dr.Close(); con.Close(); } else if(DropDownList1.Text=="SN") { string str = "SELECT * FROM ['ISB VAS Nodes
']其中SN =' + TextBox2.Text + ';
// city是表中的列名
SqlCommand cmd;
cmd = new SqlCommand(str,con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
// 如果city在表的0索引中
GridView1.DataSource = dr;
GridView1.DataBind();
}
else
{
Response.Write( 城市不存在);
}
dr.Close();
con.Close();
}
'] where SN='" + TextBox2.Text + "'"; //city is the column name in table SqlCommand cmd; cmd = new SqlCommand(str, con); SqlDataReader dr; dr = cmd.ExecuteReader(); if (dr.Read()) { //if city is in 0 index of table GridView1.DataSource = dr; GridView1.DataBind(); } else { Response.Write("City does not exist"); } dr.Close(); con.Close(); }
这篇关于gridview的下拉列表问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文