主题:请大家看一个asp.net代码,说明我的观点是否正确,谢谢
我觉得下面代码里的 else
{
Message.Text = "";
}
这段代码用不用实现的效果是一样的啊,请问 Message.Text = ""; 有什么作用啊?
<%@ Page Language="C#" %>
<script runat="server">
void Page_Load()
{
string msgCitiesList = "";
if (Page.IsPostBack == true)
if (list1.Items[0].Selected == true)
{
msgCitiesList = msgCitiesList + list1.Items[0].Text + "<br />";
}
if (list1.Items[1].Selected)
{
msgCitiesList = msgCitiesList + list1.Items[1].Text + "<br/>";
}
if (list1.Items[2].Selected)
{
msgCitiesList = msgCitiesList + list1.Items[2].Text + "<br />";
}
if (msgCitiesList != "")
{
Message.Text = "You have selected: <br />" + msgCitiesList;
}
else
{
Message.Text = "";
}
}
</script>
<html>
<head>
<title>List Box Example</title>
</head>
<body>
<asp:Label id="Message" runat="server"></asp:Label>
<br />
Which city do you wish to look at hotels for?<br />
<form runat="server">
<asp:listbox id="list1" runat="server" selectionmode="multiple">
<asp:listitem>Madrid</asp:listitem>
<asp:listitem>Oslo</asp:listitem>
<asp:listitem>Lisbon</asp:listitem>
</asp:listbox>
<br />
<input type="submit" value="Submit Query" />
</form>
</body>
</html>
{
Message.Text = "";
}
这段代码用不用实现的效果是一样的啊,请问 Message.Text = ""; 有什么作用啊?
<%@ Page Language="C#" %>
<script runat="server">
void Page_Load()
{
string msgCitiesList = "";
if (Page.IsPostBack == true)
if (list1.Items[0].Selected == true)
{
msgCitiesList = msgCitiesList + list1.Items[0].Text + "<br />";
}
if (list1.Items[1].Selected)
{
msgCitiesList = msgCitiesList + list1.Items[1].Text + "<br/>";
}
if (list1.Items[2].Selected)
{
msgCitiesList = msgCitiesList + list1.Items[2].Text + "<br />";
}
if (msgCitiesList != "")
{
Message.Text = "You have selected: <br />" + msgCitiesList;
}
else
{
Message.Text = "";
}
}
</script>
<html>
<head>
<title>List Box Example</title>
</head>
<body>
<asp:Label id="Message" runat="server"></asp:Label>
<br />
Which city do you wish to look at hotels for?<br />
<form runat="server">
<asp:listbox id="list1" runat="server" selectionmode="multiple">
<asp:listitem>Madrid</asp:listitem>
<asp:listitem>Oslo</asp:listitem>
<asp:listitem>Lisbon</asp:listitem>
</asp:listbox>
<br />
<input type="submit" value="Submit Query" />
</form>
</body>
</html>