如何优化"两个下拉列表分别邦定两个表中不同的字段"
DropDownList market_type=(DropDownList)e.Item.FindControl("DDL_market_type");
//绑定市场分类下拉菜单的值;
string strSqlDDL1 = null;
strSqlDDL 1 = "select users_mt_name1,users_mt_id1 from t_users_market_type1 ";
SqlDA 1 = new SqlDataAdapter(strSqlDDL,ClassLib.DbConn.SqlConn);
DataSet SqlDS = new DataSet();
SqlDA1.Fill(SqlDS,"t_users_market_type1 ");
market_type1.DataTextField = "users_mt_name";//出错行
market_type1.DataValueField = "users_mt_id";
market_type1.DataSource = SqlDS.Tables["t_users_market_type1 "].DefaultView;
market_type1.DataBind();
string strSqlDDL2 = null;
strSqlDDL2 = "select users_mt_name2,users_mt_id2 from t_users_market_type ";
SqlDA 2 = new SqlDataAdapter(strSqlDDL,ClassLib.DbConn.SqlConn);
SqlDA2.Fill(SqlDS,"t_users_market_type2");
market_type2.DataTextField = "users_mt_name";//出错行
market_type2.DataValueField = "users_mt_id";
market_type2.DataSource = SqlDS.Tables["t_users_market_type2 "].DefaultView;
market_type2.DataBind();
这样的代码看上去好像有很多重复性,号比如那个那2条Sql语句,应该可以用一条就行了.好比如那个SqlDA.Fill(),是不是可以一下子就可以Fill2个进去?要是能改成下面的代码多好呀,可惜运行显示不了DropDownList的内容!请问如何改进下面的代码?
string strSqlDDL1 = null;
strSqlDDL 1 = "select users_mt_name1,users_mt_id1 ,users_mt_name2,users_mt_id2 from t_users_market_type1 , t_users_market_type2 ";
SqlDA 1 = new SqlDataAdapter(strSqlDDL,ClassLib.DbConn.SqlConn);
DataSet SqlDS = new DataSet();
SqlDA1.Fill(SqlDS,"t_users_market_type1,t_users_market_type2 ");
market_type1.DataTextField = "users_mt_name";//出错行
market_type1.DataValueField = "users_mt_id";
market_type1.DataSource = SqlDS.Tables["t_users_market_type1 ,t_users_market_type2 "].DefaultView;
market_type1.DataBind();