本文介绍了Dropdownlist无法在UpdatePanel内部更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ASP网站.我想在更改下拉列表时更新文本框.但是我不使用自动回发.Dropdownlist在数据库中获取值,然后将这些值写入文本框.如何在updatePanel内部进行操作?
I have a asp web site. I want to update textboxes while change dropdownlist. But I don't use autopostback. Dropdownlist getting values in database and I'm writing into textbox this values.How can I do inside updatePanel?
index.aspx
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代码:
And My index.aspx.cs code:
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(); } } 推荐答案您将要更新的所有内容都包裹在 UpdatePanel
You wrap everything you want to update without a PostBack inside an 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 .
And you need to add a ScriptManager to the page.
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>更多推荐
Dropdownlist无法在UpdatePanel内部更新?
发布评论