[英]display a value of the text box when the button is clicked in a web form
我想在单击按钮时根据用户选择在文本框中出现一个字符串,我不知道该怎么做,这是代码:
protected void Button1_Click(object sender, EventArgs e)
{
//DECLARE A STRING VARIABLE
String choice = "";
//LET THE USER SELECT BETWEEN TWO VALUES TO DISPLAY PRICE OF THE BOOK
Response.Write("<script>choice=window.prompt('Which Currency you want the price display ? 1 : Dollar or 2: Euro');" + "if(choice=='1'){ document.writeln('$22.43');}" + "if(choice=='2') document.write(' 20.55 EUR');" + "</script>");
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
尝试这个:
字符串 yourString = "嘿嘿嘿"; TextBoxName.Text = yourString;
1.使用 label 并从 label1 编辑文本到您想要显示价格的货币? 1:美元或 2:欧元。
2.使用另一个label,您要在其中显示货币并将其命名为lbl_currency。
3.使用文本框并将其命名为 txt_choice。
4.使用按钮命名为btn,双击按钮并在点击事件中输入此代码。
protected void btn_Click(object sender, EventArgs e)
{
if(Convert.ToInt32(txt_choice.Text)==1){
lbl_currency.Text="$22.43";
}
else if(Convert.ToInt32(txt_choice.Text)==2){
lbl_currency.Text="20.55 EUR";
}
else{
MessageBox.Show("Wrong Input");
}
}
您需要有一个名为 RadioButtonList 的控件来选择您的货币,然后在代码中隐藏
protected void btn_Click(object sender, EventArgs e)
{
if(yourID_RadioButtonList.SelectedValue)=="Something"){
lbl_currency.Text="Your_Value1";
}
else {
lbl_currency.Text="Your_Value2";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.