我有2个Kendo UI Web下拉菜单,一个是客户端绑定,另一个是静态值:
<select runat="server" id="ddlCheckStatic" class="k-dropdown" style="width: auto">
<option value="One">One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</select>
<select runat="server" id="ddlCheckdynamic" class="k-dropdown" style="width: auto">
</select>
<script>
$("#ddlCheckStatic").kendoDropDownList();
var data =
[
{ text: "Black", Id: "1" },
{ text: "Orange", Id: "2" },
{ text: "Grey", Id: "3" }
];
$("#ddlCheck").kendoDropDownList({
dataValueField: "Id",
dataTextField: "text",
dataSource: data
});
</script>
有一个asp.net按钮可以进行回发
<asp:Button runat="server" ID="btn"
Text="Server Button" CssClass="k-button" OnClick="btn_Click" />
在服务器端单击其中我选择了下拉值。
protected void btn_Click(object sender, EventArgs e)
{
string _static = ddlCheckStatic.Value; // Working great :)
string _dynamic = ddlCheckdynamic.Value; // Is blank everytime :(
}
现在静态下拉,即 ddlCheckStatic 在回发时维持它的状态,并且它的选定值也可以在 btn_Click 中访问,但是相同动态的事情不会发生,即 ddlCheckdynamic 。 反正有没有从动态的那个获得相同的行为?
如果值从服务器端绑定,如下所示,那么控制就是维持它的状态。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlCheckDynamic.Items.Add(new System.Web.UI.WebControls.ListItem() { Text = "Black", Value = "1" });
ddlCheckDynamic.Items.Add(new System.Web.UI.WebControls.ListItem() { Text = "Orange", Value = "2" });
ddlCheckDynamic.Items.Add(new System.Web.UI.WebControls.ListItem() { Text = "Grey", Value = "3" });
}
}