c#如何读取下拉框的值?

读取所选择的值。谢谢。... 读取所选择的值。谢谢。 展开
 我来答
百度网友25ed0b895
2010-06-07 · TA获得超过257个赞
知道答主
回答量:128
采纳率:0%
帮助的人:0
展开全部
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);
}
}
cdlgdxgcjsxy
2010-06-07 · TA获得超过238个赞
知道小有建树答主
回答量:174
采纳率:0%
帮助的人:155万
展开全部
string value;//存储只的变量
int index = DropDownList1.SelectedIndex; //被选中的那项的索引
value = DropDownList1.Items[index].Value;//取得值
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
depluin
2010-06-07 · TA获得超过3179个赞
知道大有可为答主
回答量:3378
采纳率:75%
帮助的人:2432万
展开全部
winForm还是webForm?

用dropdownlist或者combobox的selectedItem或者selectValue
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式