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