0
我已經爲人員配置文件創建了表。我想我的DropDownList
選定的值填充我的2 Textboxes
。但是,只有DropDownList
有數據庫項目,但是當我選擇一個項目時,2 Textboxes
不會填充任何內容。我正在使用ASP.NET C#和SQL Management Studio。如果有人能幫忙,我會很高興,如果有需要在數據庫中包含查詢,請教我。謝謝!!在ASP.NET C上使用sql填充DropDownList選擇的文本框#
這裏是我的頁面加載
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ddlName1.Items.Add(new ListItem("-Select Officer-", ""));
ddlName1.AppendDataBoundItems = true;
SqlConnection connName1 = new SqlConnection("Data Source=(...);" + "Initial Catalog=(...); Integrated Security=SSPI");
connName1.Open();
SqlDataAdapter adapName1 = new SqlDataAdapter("SELECT * FROM OfficersProfile", connName1);
DataSet dsName1 = new DataSet();
adapName1.Fill(dsName1);
ddlName1.DataSource = dsName1;
ddlName1.DataTextField = "officer_name";
ddlName1.DataValueField = "officer_id";
ddlName1.DataBind();
connName1.Close();
}
}
下面的代碼是我對代碼的SelectedIndexChanged
protected void ddlName1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection connName1 = new SqlConnection("Data Source=(...);" + "Initial Catalog=(...); Integrated Security=SSPI");
connName1.Open();
SqlCommand cmdName1 = new SqlCommand("SELECT * FROM OfficersProfile where [email protected]", connName1);
cmdName1.Parameters.AddWithValue("@officerID", ddlName1.SelectedValue);
SqlDataReader drName1;
drName1 = cmdName1.ExecuteReader();
while(drName1.Read())
{
txtDivision.Text = drName1[3].ToString();
txtLSOExec.Text = drName1[4].ToString();
}
drName1.Close();
connName1.Close();
}
回傳被設置爲true添加
AutoPostBack="true"
?究竟你面臨的問題是什麼? ,錯誤還是沒有迴應? – Saurabh