[英]How to change data display in a TextBox from a DropDownList selection?
大家好,我發布了這個主題。 我真的很想知道,如何從DDL獲取可以自動更改TextBox顯示的結果。 我們的每件商品都有多個尺寸,有時,當您單擊其他尺寸時,價格會有所不同。 如何實現此功能?
任何幫助,我將不勝感激。
這是我的示例代碼:
Details.aspx:
<asp:TemplateField SortExpression="Size" ItemStyle-Wrap="True" ItemStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Bottom" HeaderStyle-Wrap="False" HeaderText="Options">
<ItemTemplate>
Size:<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SizeSource" AutoPostBack="true" DataTextField="Size" DataValueField="Size" Height="22px" Width="60px">
</asp:DropDownList>
Qty:<asp:TextBox ID="TextBox2" runat="server" Height="16px" Width="30px" Text="<%# 1 %>"></asp:TextBox>
<br />
Price(USD):
<asp:TextBox runat="server" DataSourceID="SizeSource" SortExpression="Price" DataFormatString="{0}" ID="PriceList" Width="50px" Height="16px" ValidationGroup="Price" AutoPostBack="True" />
<asp:SqlDataSource ID="SizeSource" runat="server" ConnectionString="<%$ ConnectionStrings:LIFEbabySAP %>" SelectCommand="SELECT left(T0.ItemCode,8) as Image, left(T0.ItemCode,8) as Code, T0.U_ItemName as Name, T0.U_Size as Size, T0.U_Colour as Color,case T1.Onhand when 0 then 'Out of Stock' else 'In Stock' end as Availability, T0.UserText as Description, CAST(T2.Price as Int)as Price FROM OITM T0 inner join oitw T1 on T0.ItemCode = T1.Itemcode inner join itm1 T2 on T0.ItemCode = T2.ItemCode WHERE (left(T0.ItemCode,8) = @Image) and T0.U_USE = 'Y' and T1.Onhand != 0 and T1.whscode ='BAW' and T2.PriceList = 10">
<SelectParameters>
<asp:QueryStringParameter Name="Image" QueryStringField="product" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</ItemTemplate>
<HeaderStyle Wrap="False"></HeaderStyle>
<ItemStyle HorizontalAlign="Left" VerticalAlign="Bottom" Wrap="True"></ItemStyle>
</asp:TemplateField>
Catalog.aspx.cs CodeBehind(C#):
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
string Size = Request.QueryString["Price"];
if (Size != null)
{
ddlCategory.SelectedValue = Size;
}
}
ItemsGet();
}
protected void CatalogList_SelectedIndexChanged(object sender, EventArgs e)
{
string Image = CatalogList.SelectedValue.ToString().Trim();
string catid = ddlCategory.SelectedValue;
Response.Redirect("Details.aspx?product="
+ Image
+ "&Price="
+ catid);
}
您是否還可以指定更多內容,是否想要使用下拉值並將其放在文本框中? 這是否將在服務器控件中(例如,gridview,datalist等...)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.