如果大类DropDownList1,有
AA
BB
CC
DD,
现在DropDownList1=BB;我点修改时显示效果如下。
BB
BB
CC
DD其中AA不见了,被BB取代了,怎么样才能正确的显示
BB
AA
BB
CC
DD我说的是点下拉框的时,里边显示的数据。。
代码如下
protected void show()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["webtest"].ToString();
conn.Open(); string sqlss = "select * from Hover_Products where ID='" + Request["ID"]+"'";
SqlCommand cmds = new SqlCommand(sqlss, conn);
DataSet sets = new DataSet();
SqlDataAdapter drs = new SqlDataAdapter();
drs.SelectCommand = cmds;
drs.Fill(sets); if (sets.Tables[0].Rows.Count > 0)
{
this.title.Text = sets.Tables[0].Rows[0]["Product_Title"].ToString().Trim();
this.p_ID.Text = sets.Tables[0].Rows[0]["Product_ID"].ToString().Trim();
this.HtmlEditor1.Text = sets.Tables[0].Rows[0]["Product_News"].ToString().Trim();
string c1= sets.Tables[0].Rows[0]["PClass"].ToString();
string c2=sets.Tables[0].Rows[0]["PSmallClass"].ToString();
string c3=sets.Tables[0].Rows[0]["PSmallClass1"].ToString(); SqlCommand cd = new SqlCommand();
cd.Connection = conn;
cd.CommandText = "select * from Hover_BigClassNews";
DataSet se = new DataSet();
SqlDataAdapter dr = new SqlDataAdapter();
dr.SelectCommand = cd;
dr.Fill(se); if (se.Tables[0].Rows.Count > 0)
{
this.DropDownList1.DataSource=se;
this.DropDownList1.DataTextField="BCNews_Name";
this.DropDownList1.DataValueField="BCNews_ID";
this.DropDownList1.AutoPostBack=true;
this.DropDownList1.DataBind(); //if (se.Tables[0].Rows[0]["BCNews_Name"].ToString() == c1.Trim())
//{
this.DropDownList1.SelectedItem.Text = c1.Trim();
//} SqlCommand cd1 = new SqlCommand();
cd1.Connection = conn;
cd1.CommandText = "select * from Hover_Small1";
DataSet se1 = new DataSet();
SqlDataAdapter dr1 = new SqlDataAdapter();
dr1.SelectCommand = cd1;
dr1.Fill(se1); if (se1.Tables[0].Rows.Count > 0)
{
this.DropDownList2.DataSource = se1;
this.DropDownList2.DataTextField = "Small1_Name";
this.DropDownList2.DataValueField = "Small1_ID";
this.DropDownList2.AutoPostBack = true;
this.DropDownList2.DataBind();
this.DropDownList2.SelectedItem.Text = c2.Trim(); SqlCommand cd2 = new SqlCommand();
cd2.Connection = conn;
cd2.CommandText = "select * from Hover_Small2"; DataSet se2 = new DataSet();
SqlDataAdapter dr2 = new SqlDataAdapter();
dr2.SelectCommand = cd2;
dr2.Fill(se2); if (se2.Tables[0].Rows.Count > 0)
{
this.DropDownList3.DataSource = se2;
this.DropDownList3.DataTextField = "Small2_Name";
this.DropDownList3.DataValueField = "Small2_ID";
this.DropDownList3.AutoPostBack = true;
this.DropDownList3.DataBind();
this.DropDownList3.SelectedItem.Text = c3.Trim();
}
else
{
this.DropDownList3.Enabled = false;
this.DropDownList3.AutoPostBack = false;
this.DropDownList3.SelectedItem.Text = "";
} dr2.Dispose();
dr2 = null;
}
else
{
this.DropDownList2.Enabled = false;
this.DropDownList2.SelectedItem.Text = "";
this.DropDownList3.Enabled = false;
this.DropDownList3.SelectedItem.Text = "";
} dr1.Dispose();
dr1 = null;
//this.DropDownList3.SelectedItem.Text= c3.Trim();
} dr.Dispose();
dr = null;
} drs.Dispose();
drs = null;
conn.Close();
}
AA
BB
CC
DD,
现在DropDownList1=BB;我点修改时显示效果如下。
BB
BB
CC
DD其中AA不见了,被BB取代了,怎么样才能正确的显示
BB
AA
BB
CC
DD我说的是点下拉框的时,里边显示的数据。。
代码如下
protected void show()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["webtest"].ToString();
conn.Open(); string sqlss = "select * from Hover_Products where ID='" + Request["ID"]+"'";
SqlCommand cmds = new SqlCommand(sqlss, conn);
DataSet sets = new DataSet();
SqlDataAdapter drs = new SqlDataAdapter();
drs.SelectCommand = cmds;
drs.Fill(sets); if (sets.Tables[0].Rows.Count > 0)
{
this.title.Text = sets.Tables[0].Rows[0]["Product_Title"].ToString().Trim();
this.p_ID.Text = sets.Tables[0].Rows[0]["Product_ID"].ToString().Trim();
this.HtmlEditor1.Text = sets.Tables[0].Rows[0]["Product_News"].ToString().Trim();
string c1= sets.Tables[0].Rows[0]["PClass"].ToString();
string c2=sets.Tables[0].Rows[0]["PSmallClass"].ToString();
string c3=sets.Tables[0].Rows[0]["PSmallClass1"].ToString(); SqlCommand cd = new SqlCommand();
cd.Connection = conn;
cd.CommandText = "select * from Hover_BigClassNews";
DataSet se = new DataSet();
SqlDataAdapter dr = new SqlDataAdapter();
dr.SelectCommand = cd;
dr.Fill(se); if (se.Tables[0].Rows.Count > 0)
{
this.DropDownList1.DataSource=se;
this.DropDownList1.DataTextField="BCNews_Name";
this.DropDownList1.DataValueField="BCNews_ID";
this.DropDownList1.AutoPostBack=true;
this.DropDownList1.DataBind(); //if (se.Tables[0].Rows[0]["BCNews_Name"].ToString() == c1.Trim())
//{
this.DropDownList1.SelectedItem.Text = c1.Trim();
//} SqlCommand cd1 = new SqlCommand();
cd1.Connection = conn;
cd1.CommandText = "select * from Hover_Small1";
DataSet se1 = new DataSet();
SqlDataAdapter dr1 = new SqlDataAdapter();
dr1.SelectCommand = cd1;
dr1.Fill(se1); if (se1.Tables[0].Rows.Count > 0)
{
this.DropDownList2.DataSource = se1;
this.DropDownList2.DataTextField = "Small1_Name";
this.DropDownList2.DataValueField = "Small1_ID";
this.DropDownList2.AutoPostBack = true;
this.DropDownList2.DataBind();
this.DropDownList2.SelectedItem.Text = c2.Trim(); SqlCommand cd2 = new SqlCommand();
cd2.Connection = conn;
cd2.CommandText = "select * from Hover_Small2"; DataSet se2 = new DataSet();
SqlDataAdapter dr2 = new SqlDataAdapter();
dr2.SelectCommand = cd2;
dr2.Fill(se2); if (se2.Tables[0].Rows.Count > 0)
{
this.DropDownList3.DataSource = se2;
this.DropDownList3.DataTextField = "Small2_Name";
this.DropDownList3.DataValueField = "Small2_ID";
this.DropDownList3.AutoPostBack = true;
this.DropDownList3.DataBind();
this.DropDownList3.SelectedItem.Text = c3.Trim();
}
else
{
this.DropDownList3.Enabled = false;
this.DropDownList3.AutoPostBack = false;
this.DropDownList3.SelectedItem.Text = "";
} dr2.Dispose();
dr2 = null;
}
else
{
this.DropDownList2.Enabled = false;
this.DropDownList2.SelectedItem.Text = "";
this.DropDownList3.Enabled = false;
this.DropDownList3.SelectedItem.Text = "";
} dr1.Dispose();
dr1 = null;
//this.DropDownList3.SelectedItem.Text= c3.Trim();
} dr.Dispose();
dr = null;
} drs.Dispose();
drs = null;
conn.Close();
}
解决方案 »
- aspx页面中如何正确添加keywords和descripiton
- vs2008 asp.net Treeview 如何点击结点将网页载入指定框架
- 小弟用GridView实现删除行,遇到个怪问题!希望大哥,们来帮看看
- [难]Asp.net 默认的调试器为IE,可以修改不?比如firefox
- 大家好哪位高手给我个好例子啊用ASP.NET输入指定内容到一个新的WORD文档里?
- 如何统计当天访问的人数?
- 费解的问题,对我来说,谁解决一下,愿百分想送
- 求助:数据库链接时出错:拒绝了对对象 'notice'(数据库 'gyzxstu',所有者 'dbo')的 SELECT 权限
- GGJJ: 假如数据库里有这么个字符串:string dd="-LJF-789-111"; “-”是分隔符号,现在我怎么读出 LJF 和 789 和 111 ?
- dropdownlist能不能在付初值的时候给TXT值赋值!
- gridview中的hyperlinkfield问题?
- 急!VWD2008开发的网站IIS上发布不了啊。
{
if(li.Text=="A")
{
li.Selected=true;
}
}
或用索引
{
this.DropDownList1.SelectedItem.Text = c1.Trim();
}
如果数据库中有这个值,就把把付给dropdownlist1,但是se.Tables[0].Rows[0]["BCNews_Name"].ToString()
只取第一个值,怎样才能让它验索一下数据库中有没有这个数据