vb.net 你如何在c#的下拉列表中使用if条件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26381378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you use an if condition in a dropdownlist in c#
提问by user3196662
I have the following ASP.net code that I want to port to C#.
我有以下 ASP.net 代码要移植到 C#。
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If DropDownList1.SelectedItem.Text = "1" Then
Response.Redirect("default.aspx")
ElseIf DropDownList1.SelectedItem.Text = "2" Then
Response.Redirect("default.aspx")
End If
End Sub
How should I go about this?
我该怎么办?
回答by krystan honour
The code translated to c# is
翻译成c#的代码是
protected void Button1_Click (Object sender, EventArgs e)
{
if (DropDownList1.SelectedItem.Text == "1")
{
Response.Redirect("default.aspx");
}
else if (DropDownList1.SelectedItem.Text == "2")
{
Response.Redirect("default.aspx");
}
}
Note there is no 'Handles' statement in c# to attach the event to the handler to use the below code in your Initialisation stages.
请注意,c# 中没有“句柄”语句将事件附加到处理程序以在初始化阶段使用以下代码。
Button1.Click += Button1_Click;
回答by Santosh Panda
So here goes your C# equivalent code:
所以这里是你的 C# 等效代码:
protected void Button1_Click(object sender, System.EventArgs e)
{
if (DropDownList1.SelectedItem.Text == "1") {
Response.Redirect("default.aspx");
} else if (DropDownList1.SelectedItem.Text == "2") {
Response.Redirect("default.aspx");
}
}
Sometimes you better use some online converter which are readily available with zero cost.
有时,您最好使用一些零成本随时可用的在线转换器。
回答by asdf_enel_hak
When use http://www.developerfusion.com/tools/convert/vb-to-csharp/conversion link
当使用http://www.developerfusion.com/tools/convert/vb-to-csharp/转换链接时
protected void Button1_Click(object sender, System.EventArgs e)
{
if (DropDownList1.SelectedItem.Text == "1") {
Response.Redirect("default.aspx");
} else if (DropDownList1.SelectedItem.Text == "2") {
Response.Redirect("default.aspx");
}
}

