我有一个asp网站。我想在更改下拉列表时更新文本框。但是我没有使用自动回复。下拉列表在数据库中获取值,并且我将这些值写入文本框。我如何在updatePanel内部进行操作?
的Index.aspx
<div class="col-sm-8">
<asp:DropDownList ID="drp_MalAd" Width="130px" CssClass="form-control center-block" runat="server" AutoPostBack="true" DataSourceID="SqlDataSourceMalAd" DataTextField="MALAD" DataValueField="MALAD" OnSelectedIndexChanged="drp_MalAd_SelectedIndexChanged"></asp:DropDownList>
<asp:SqlDataSource runat="server" ID="SqlDataSourceMalAd" ConnectionString='<%$ ConnectionStrings:... %>' SelectCommand="SELECT ..."></asp:SqlDataSource>
</div>
我的index.aspx.cs代码:
protected void drp_MalAd_SelectedIndexChanged(object sender, EventArgs e)
{
string malAdi = drp_MalAd.SelectedItem.Text.ToString();
SqlDataReader reader;
SqlCommand cmd = new SqlCommand("SELECT .. WHERE MALAD='" + malAdi + "'", con);
SqlCommand cmd1 = new SqlCommand("SELECT ...WHERE MALAD='" + malAdi + "'", con);
SqlCommand cmd2 = new SqlCommand("SELECT ... WHERE MALAD='" + malAdi + "'", con);
SqlCommand cmd3 = new SqlCommand("SELECT ... WHERE MALAD='" + malAdi + "'", con);
try
{
con.Open();
txt_AnaBirim.Text = cmd.ExecuteScalar().ToString();
txt_malKodu.Text = cmd1.ExecuteScalar().ToString();
txt_KDVOranim.Text = cmd2.ExecuteScalar().ToString();
con.Close();
}
catch (Exception)
{
}
try
{
con.Open();
reader = cmd3.ExecuteReader();
grd_StokDurumu.DataSource = reader;
grd_StokDurumu.DataBind();
reader.Close();
}
catch
{
}
finally
{
con.Close();
}
}
答案 0 :(得分:1)
在UpdatePanel
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="drp_MalAd" Width="130px" CssClass="form-control center-block" runat="server" AutoPostBack="true" DataSourceID="SqlDataSourceMalAd" DataTextField="MALAD" DataValueField="MALAD" OnSelectedIndexChanged="drp_MalAd_SelectedIndexChanged"></asp:DropDownList>
<asp:SqlDataSource runat="server" ID="SqlDataSourceMalAd" ConnectionString='<%$ ConnectionStrings:... %>' SelectCommand="SELECT ..."></asp:SqlDataSource>
<asp:TextBox ID="txt_AnaBirim" runat="server"></asp:TextBox>
<asp:TextBox ID="txt_malKodu" runat="server"></asp:TextBox>
<asp:TextBox ID="txt_KDVOranim" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
您需要在页面中添加ScriptManager
。
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>