PDA

View Full Version : Using ArrayList for combobox



studentdev
Jan 26, 2010, 12:51 PM
Hi,

I'm new to this and am trying to implement a combobox. I tried looking at the examples, but the values are hardcoded. In my case, it has to be dynamic.. I have my options that I want to be listed in an ArrayList (I'm using c#).. I'm wondering how I can connect the ArrayList to the store.. Here's a bit of the code..


ArrayList alFolders = new ArrayList();

foreach (System.IO.DirectoryInfo dinfo in m_dir.GetDirectories("*.*"))
{
alFolders.Add(dinfo.Name.ToString());
}


<ext:Store ID="Store1" runat="server" AutoLoad="true">
<Reader>
<ext:ArrayReader>
<Fields>

<ext:RecordField Name="project" />

</Fields>
</ext:ArrayReader>
</Reader>
</ext:Store>


<ext:ComboBox ID="ComboBox1" runat="server" DisplayField="state"
Editable="false" EmptyText="Select a project..." ForceSelection="true"
ItemSelector="div.list-item" Mode="Local" Select&#111;nfocus="true" StoreID="Store1"
TriggerAction="All" TypeAhead="true" ValueField="project" Width="250" CausesValidation="true">
<Template ID="Template1" runat="server">
<tpl for=".">
<div class="list-item">
<h3>{state}</h3>



</tpl>
</Template>
</ext:ComboBox>



Thanks!

geoffrey.mcgill
Jan 26, 2010, 7:51 PM
Hi studentdev,

Here's a basic ComboBox + Store sample which demonstrates listing all the current directories.

Example


<%@ Page Language="C#" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Linq" %>

<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
var names = new DirectoryInfo(Directory.GetCurrentDirectory())
.GetDirectories()
.ToList()
.ConvertAll(dir => new string[] { dir.Name })
.ToArray();

this.Store1.DataSource = names;
this.Store1.DataBind();
}
}
</script>

<!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 id="Head1" runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:Store ID="Store1" runat="server">
<Reader>
<ext:ArrayReader>
<Fields>
<ext:RecordField Name="name" />
</Fields>
</ext:ArrayReader>
</Reader>
</ext:Store>

<ext:ComboBox ID="ComboBox1" runat="server" DisplayField="name" StoreID="Store1" />
</form>
</body>
</html>

The sample is written for v1.0, although will work in v0.8.x with a little modification of the namespace.

Hope this helps.

geoffrey.mcgill
Jan 26, 2010, 7:52 PM
Out of interests sake, heres a sample demonstrating an alternative <ext:Store> markup syntax for v1.0.

Example


<%@ Page Language="C#" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Linq" %>

<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
var names = new DirectoryInfo(Directory.GetCurrentDirectory())
.GetDirectories()
.ToList()
.ConvertAll(dir => new string[] { dir.Name })
.ToArray();

this.ComboBox1.Store.Primary.DataSource = names;
this.ComboBox1.Store.Primary.DataBind();
}
}
</script>

<!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 id="Head1" runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:ComboBox ID="ComboBox1" runat="server" DisplayField="name">
<Store>
<ext:Store runat="server">
<Reader>
<ext:ArrayReader>
<Fields>
<ext:RecordField Name="name" />
</Fields>
</ext:ArrayReader>
</Reader>
</ext:Store>
</Store>
</ext:ComboBox>
</form>
</body>
</html>

Hope this helps.