我想選擇一個服務器,並只獲取服務器的數據庫名稱選擇,但在此代碼..給我所有服務器的所有數據庫!請問有什麼解決辦法?ASP.NET MVC 5 DropDownList selectedindexchanged
控制器
List<SelectListItem> allServer = new List<SelectListItem>();
List<SelectListItem> alldatabases = new List<SelectListItem>();
allServer.Add(new SelectListItem() { Text = "Please Select DataBase...", Value = "", Selected = true });
System.Data.Sql.SqlDataSourceEnumerator instance = System.Data.Sql.SqlDataSourceEnumerator.Instance;
System.Data.DataTable dt = instance.GetDataSources();
List<string> ddlInstances = new List<string>();
foreach (DataRow dr in dt.Rows)
{
dr["InstanceName"]));
ServerConnection Conn;
Conn = new ServerConnection();
Conn.ServerInstance = string.Concat(dr["ServerName"], "\\", dr["InstanceName"]);
allServer.Add(new SelectListItem() { Text = Conn.ServerInstance, Value = Conn.ServerInstance, Selected = true });
Server Ser = new Server(Conn);
foreach (Database db in Ser.Databases)
{
alldatabases.Add(new SelectListItem() { Text = db.Name, Value = db.Name, Selected = false });
}
查看
@using (Html.BeginForm("Index", "Connect", FormMethod.Get))
{
Server Names
@Html.DropDownList("SerNames")
DB Names
@Html.DropDownList("DBNames")
我想選擇一臺服務器,並獲得該服務器的數據庫名稱,但在這段代碼中,我得到的所有服務器的所有數據庫,該如何解決? –
編輯你的問題,解釋問題(不在評論中) –
done!,plz幫助 –