邦定數據方法一
DataTable dt_game = new DataTable();
string sql_game = "SELECT GamesID,CName,Season,type FROM Games_Info order by Cname";
dt_game = conn.ExecuteSelectTable(sql_game);
ListItem first_Item = new ListItem();
first_Item.Value = "0";
first_Item.Text = "";
GamesID.Items.Add(first_Item);
// MatchID.Items.Add(first_Item);
foreach (DataRow dr in dt_game.Rows)
{
ListItem li_game = new ListItem();
li_game.Text = dr["CName"].ToString();
li_game.Value = dr["GamesID"].ToString();
GamesID.Items.Add(li_game);
}
方法二
string sql = "SELECT * FROM Nations_Info order by CName";
dbconnection conn = new dbconnection();
DataTable dt = new DataTable();
dt = conn.ExecuteSelectTable(sql);
nationid.DataSource = dt.DefaultView;
nationid.DataTextField = "CName"; //dropdownlist的Text的字段
nationid.DataValueField = "NationID";//dropdownlist的Value的字段
nationid.DataBind();
取得他選項的value
dbconnection conn = new dbconnection();
DataTable dt_match = new DataTable();
string sql_match = "select m.MatchID,t1.CName as HomeTeamCName,t2.CName as AwayTeamCname,m.StartTime from Matchs_Info m inner join Teams_Info t1 on m.HomeTeamID = t1.TeamID inner join Teams_Info t2 on m.AwayTeamID = t2.TeamID where m.flag=3 and m.GamesID= " + GamesID.SelectedValue.ToString() + " order by m.matchid desc";
dt_match = conn.ExecuteSelectTable(sql_match);
foreach (DataRow dr in dt_match.Rows)
{
ListItem li_match = new ListItem();
li_match.Text = dr["HomeTeamCName"].ToString() + " VS " + dr["AwayTeamCname"].ToString() + dr["StartTime"].ToString();
li_match.Value = dr["matchid"].ToString();
MatchID.Items.Add(li_match);
}
}
//在他的SelectedIndexChanged(事件(雙擊控件即可),取得gameid選擇的value爲 GamesID.SelectedValue.ToString()