從下拉列表中選擇一個值時遇到問題。無論我選擇什麼,只有第一個值始終選擇。請幫助...從下拉列表中選擇一個值的問題
這裏是代碼...
protected void Button4_Click(object sender, EventArgs e)
{
SqlConnection con;
String strcon = ConfigurationManager.AppSettings["Constr"].ToString();
try
{
if (!IsPostBack)
{
con = new SqlConnection(strcon);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select user_name from user_details where role='USER'", con);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList1.DataTextField = "user_name";
DropDownList1.DataSource = ds.Tables[0].DefaultView;
DropDownList1.DataBind();
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
protected void Button6_Click(object sender, EventArgs e)
{
string Name = Session["name"].ToString();
SqlConnection con;
String strcon = ConfigurationManager.AppSettings["Constr"].ToString();
try
{
con = new SqlConnection(strcon);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select user_name,Arival,late,Day_count from attedance where user_name='" + DropDownList1.SelectedItem.Text + "' ", con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
這是運行在UpdatePanel或類似的東西嗎?否則,你需要在Page_Load – Tchami 2010-08-18 08:27:36
上選擇一個項目,它用於從表 – Alivia 2010-08-18 08:34:25
中獲取值,非常感謝.......它必須在頁面加載中給出我把它錯誤地放在按鈕控制中,它現在正在工作。 。:) – Alivia 2010-08-18 09:07:06