如何更新下拉列表中更改的选定索引上的标签 [英] how can i update a label on selected index changed in dropdown

查看:72
本文介绍了如何更新下拉列表中更改的选定索引上的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:DropDownList ID="DropDownList1" runat="server" 

                onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                <asp:ListItem>1
                <asp:ListItem>2
                <asp:ListItem>3
                <asp:ListItem>4
                <asp:ListItem>5
                <asp:ListItem>6



这是一个下拉菜单


this is a dropdown

<asp:Label ID="Label2" runat="server" Text="Label">



这是一个标签



现在我想要更新选择下拉列表或更改下拉列表中的标签,更新应由ajax执行,我自己的代码在此事件上:


and this is a label

now i want to update a label on select of dropdown or change in dropdown and the updation shou ld be performed by ajax and i hv my own code on this event:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {
       int factor = DropDownList1.SelectedIndex + 1;
       int pricein = int.Parse(Label2.Text);
       int totalPrice = pricein * factor;
       Label2.Text = totalPrice.ToString();
   }

推荐答案

设置 AutoPostBack =true


<asp:label id="Label2" runat="server" xmlns:asp="#unknown">Text="Label"></asp:label>



这里文本 标签 Label 并在以下行中将其解析为整数。


Here Text of Label is "Label" and in the following line you are parsing it to integer.

int pricein = int.Parse(Label2.Text);





什么将是输出? :)



同样如 thatraja 建议,你应该设置 AutoPostBack =true for DropDownList 以便触发 DropDownList1_SelectedIndexChanged 事件。



What will be the output? :)

Also as thatraja suggested, you should set AutoPostBack="true" for DropDownList in order to fire DropDownList1_SelectedIndexChanged Event.


这篇关于如何更新下拉列表中更改的选定索引上的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆