3个回答
展开全部
DropDownList.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DropDownList.aspx.cs" Inherits="DropDownList" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DropDownList</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="Sample1_Text" Value="Sample1_Value"></asp:ListItem>
<asp:ListItem Text="Sample2_Text" Value="Sample2_Value"></asp:ListItem>
<asp:ListItem Text="Sample3_Text" Value="Sample3_Value"></asp:ListItem>
<asp:ListItem Text="Sample4_Text" Value="Sample4_Value"></asp:ListItem>
<asp:ListItem Text="Sample5_Text" Value="Sample5_Value"></asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>
DropDownList.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class DropDownList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
LiteralControl li = new LiteralControl();
li.Text = "Selected Value : " + DropDownList1.SelectedItem.Value;
Page.Controls.Add(li);
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DropDownList.aspx.cs" Inherits="DropDownList" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DropDownList</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="Sample1_Text" Value="Sample1_Value"></asp:ListItem>
<asp:ListItem Text="Sample2_Text" Value="Sample2_Value"></asp:ListItem>
<asp:ListItem Text="Sample3_Text" Value="Sample3_Value"></asp:ListItem>
<asp:ListItem Text="Sample4_Text" Value="Sample4_Value"></asp:ListItem>
<asp:ListItem Text="Sample5_Text" Value="Sample5_Value"></asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>
DropDownList.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class DropDownList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
LiteralControl li = new LiteralControl();
li.Text = "Selected Value : " + DropDownList1.SelectedItem.Value;
Page.Controls.Add(li);
}
}
展开全部
string value;//存储只的变量
int index = DropDownList1.SelectedIndex; //被选中的那项的索引
value = DropDownList1.Items[index].Value;//取得值
int index = DropDownList1.SelectedIndex; //被选中的那项的索引
value = DropDownList1.Items[index].Value;//取得值
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
winForm还是webForm?
用dropdownlist或者combobox的selectedItem或者selectValue
用dropdownlist或者combobox的selectedItem或者selectValue
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询