why dropdownlist don't bind
private void GetSourceListData()string cmdText = "SECECT powerid,powername from power";
DataTable table =ReturnSqlex(cmdText);
SoureList.DataSource = table.DefaultView;
SoureList.DataTextField = "powername";
SoureList.DataValueField = "powerid";
SoureList.DataBind();
SoureList.Items.Insert(0, new ListItem("请选择", ""));
SoureList.DataBind();
}
public DataTable ReturnSqlex(string strSql)//调用此方法返回一个datatable
{
SqlConnection con = new SqlConnection(
ConfigurationSettings.AppSettings["SQLCONNECTIONSTRING"]);
try
{
con.Open();
SqlCommand cmd = new SqlCommand(strSql, con);
SqlDataAdapter sdr = new SqlDataAdapter();
sdr.SelectCommand = cmd;
DataSet ds = new DataSet();
sdr.Fill(ds, "table");
return ds.Tables["table"];
}
catch (SqlException ex)
{
//抛出异常
throw new Exception(ex.Message, ex);
}
finally
{ ///关闭链接
con.Close();
}
}