本帖最后由 yygy 于 2013-7-3 09:47 编辑
DropDownList1动态增加数据,当数据(3)不存在时,按回车可以增加数据,但DropDownList1.SelectedValue 下拉框的位置不对,怎样解决,请老大解决一下。图1是运行的结果,但我想要的结果是图2
<body>
<form id="form1" runat="server">
<x ageManager ID=" ageManager1" runat="server" />
<x ropDownList runat="server" ID="DropDownList1" EnableEdit="true" ForceSelection="false">
</x ropDownList>
<x:TextBox runat="server" Hidden="true" ID="TextBox1">
</x:TextBox>
</form>
</body>
<script type="text/javascript">
function onReady() {
DropDownList1 = Ext.getCmp('<%= DropDownList1.ClientID %>');
DropDownList1.on("specialkey", function (box, e) {
if (e.getKey() == e.ENTER || e.getKey() == 9) {
if (box.lastQuery != "" && box.lastQuery != undefined) {
if (confirm("输入无效,是否要新增数据?")) {
__doPostBack("DropDownList1", box.lastQuery);
}
}
}
});
}
</script>
protected void Page_Load(object sender, EventArgs e)
{
string controlName = Request.Params.Get("__EVENTTARGET");
string eventArgument = Request.Params.Get("__EVENTARGUMENT");
if (controlName == "DropDownList1")
{
DropDownList1.Items.Add(new FineUI.ListItem(eventArgument, eventArgument));
DropDownList1.SelectedValue = eventArgument;
}
if (!IsPostBack)
{
BindStringListToDropDownList();
}
}
private void BindStringListToDropDownList()
{
List<string> strList = new List<string>();
strList.Add("1");
strList.Add("2");
DropDownList1.DataSource = strList;
DropDownList1.DataBind();
}
}
|