如何在下拉列表的选定索引更改上更改按钮的文本 [英] how to change a button's text on selected index change of dropdown list
问题描述
朋友们,
我正在使用Vs 2005,asp.net,c#
如何在下拉列表的选定索引更改上更改按钮的文本?
在此先感谢
preejo
Hi friends,
I am using Vs 2005 ,asp.net,c#
how to change a button''s text on selected index change of dropdown list ?
Thanks in advance
preejo
推荐答案
在selectedIndexChanged事件上,您编写以下代码
On the selectedIndexChanged event you write following code
button1.Text = "New Text";
如果要在下拉列表中选择项目,可以尝试以下操作.
If you want to get the item selected in the dropdown, you can try following.
button1.Text = comboBox1.SelectedItem.ToString();
希望能有所帮助.如果是这样,请将其标记为答案/赞.
Milind
Hope that helps. If it does, mark it as answer/upvote.
Milind
以下是示例
在下拉列表中,将AutoPostBack属性设置为true.
Here is a sample
In your dropdownlist you set the AutoPostBack property to true.
<asp:DropDownList ID="ddl1" runat="server" OnSelectedIndexChanged = "ddl1_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
</asp:DropDownList>
这是在下拉列表的选定索引更改事件中将更改文本的按钮.
Here is the button for which the text will be changed in the selected index change event of drop down.
<asp:Button ID="btn1" runat="server" Text="submit"/>
在文件后面的代码中,使用按钮的Text属性更改按钮的文本,如下所示
In your code behind file change the text of the button using its Text property as shown below
protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
btn1.Text = ddl1.SelectedItem.Text;
}
这篇关于如何在下拉列表的选定索引更改上更改按钮的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!