我有一个.aspx页面
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="DropdownList.aspx.cs" Inherits="Test_WSMS_TV.DropdownList" EnableEventValidation="false" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
// alert('akash');
$(document).ready(function () {
//var arr = ["val1", "val2", "val3"];
//alert('akash');
// $("#DropDownList1").prepend('<option value="akash">akash</option>');
$("#DropDownList1").append(new Option('option1', 'option1'));
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" ClientIDMode="Static">
<asp:ListItem>A</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<br />
<br />
</asp:Content>
和文件后面的代码是
protected void Button1_Click(object sender, EventArgs e)
{
//var selectedOption = Request["DropDownList1"];
// DropDownList1.SelectedValue
Response.Write(DropDownList1.SelectedValue);
}
当我单击按钮时,所选的服务器控件值(&#34; A&#34;)正在显示但是
动态添加的值未显示在DropDownList1.SelectedValue
属性。如何在.cs文件中获取动态添加的值。