dropdownlist下拉框加--请选择---

public static DataSet ReturnDataSet(string SqlStr, string tablename)
{
SqlConnection con = new SqlConnection(GetConStr());
con.Open();//打开数据库连接
SqlDataAdapter ada = new SqlDataAdapter(SqlStr, con);
DataSet ds = new DataSet();
ada.Fill(ds, tablename);
return ds;
}

 

 

//SqlConnection con = new SqlConnection(Class1.lianjie());
//con.Open();
string cmdCityText = "SELECT * FROM [area] order by proid desc";
DataSet ds = new DataSet();

ds= MyClass.ReturnDataSet(cmdCityText,"aa");
//SqlCommand cmd = new SqlCommand(cmdCityText, con);
// SqlDataReader sdr = cmd.ExecuteReader();
//this.area.DataSource = sdr;

//this.area.DataTextField = "proname";//文本内容
//this.area.DataValueField = "proid"; //数据源字段
//this.area.DataBind();
//ListItem list = new ListItem("--请选择区域--", "-1 ");
//list.Selected = true;
//area.Items.Add(list);
area.Items.Clear();
ListItem item = new ListItem("-请选择区域-");
area.Items.Add(item);
foreach (DataRow dr in ds.Tables[0].Rows)
{
item = new ListItem();
item.Text = dr["proname"].ToString();
item.Value = dr["proid"].ToString();
area.Items.Add(item);
}

posted @ 2017-07-31 15:40  sky110  阅读(569)  评论(0编辑  收藏  举报