Feb 02, 2012, 7:44 AM
[CLOSED] Set initial value in DateTime combobox
Hi,
Just simply trying to set the value in a server side, dynamically configured combo box.
Why doesn't this work? It sets the value, but doesn't pick the correct item in the list with the corresponding value.
Just simply trying to set the value in a server side, dynamically configured combo box.
Why doesn't this work? It sets the value, but doesn't pick the correct item in the list with the corresponding value.
<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<ext:ResourceManager ID="extResourceManager" runat="server" />
<script type="C#" runat="server">
public class DateRange
{
public DateRange(string name, DateTime startDate)
{
this.Name = name;
this.StartDate = startDate;
}
public DateTime StartDate { get; set; }
public string Name { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest && !this.IsPostBack)
{
System.Collections.Generic.List<DateRange> ranges = new System.Collections.Generic.List<DateRange>();
ranges.Add(new DateRange("Range1", DateTime.Parse("01/01/2011")));
ranges.Add(new DateRange("Range2", DateTime.Parse("01/02/2011")));
ranges.Add(new DateRange("Range3", DateTime.Parse("01/03/2011")));
ranges.Add(new DateRange("Range4", DateTime.Parse("01/04/2011")));
this.cbRangeStart.ValueField = "StartDate";
this.cbRangeStart.DisplayField = "Name";
JsonReader reader = new JsonReader();
reader.Fields.Add("StartDate", RecordFieldType.Date);
reader.Fields.Add("Name");
var store = new Store();
store.ID = string.Format("{0}_store", this.cbRangeStart.ID);
store.Reader.Add(reader);
store.DataSource = ranges;
this.cbRangeStart.Store.Add(store);
store.DataBind();
//try to select a value
//this.cbRangeStart.SelectByValue(DateTime.Parse("01/02/2011").ToString());
this.cbRangeStart.SetValue(DateTime.Parse("01/02/2011"));
//this.cbRangeStart.SelectedItem.Value = DateTime.Parse("01/02/2011").ToString();
//this.cbRangeStart.SelectedItem.Value = "01/02/2011";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:Panel Layout="FormLayout" ID="FormLayout1" runat="server">
<Items>
<ext:ComboBox ID="cbRangeStart" runat="server" Editable="false" TypeAhead="true">
</ext:ComboBox>
</Items>
</ext:Panel>
</div>
</form>
</body>
</html>
Last edited by Daniil; Feb 02, 2012 at 10:31 AM.
Reason: [CLOSED]