Dropdownlist无法在UpdatePanel内部更新?

编程入门 行业动态 更新时间:2024-10-28 11:29:30
本文介绍了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内部更新?

本文发布于:2023-11-25 00:16:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627513.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Dropdownlist   UpdatePanel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!