2

我正在使用 Ext.Net 开发一个 Web 应用程序。

如何从数据库绑定组合框?

这是我的查询:

dynamic getRegions = (
    from region in db.Regions 
    orderby region.RgnName 
    select region.RgnName);
4

3 回答 3

2

据我所知,您必须这样做Ext.Net.ComboBoxExt.Net.Store例如:

<!-- In SamplePage.aspx -->
<ext:ResourceManager runat="server"></ext:ResourceManager>
<ext:Store runat="server" ID="Store1">          
    <Reader>
        <ext:JsonReader IDProperty="Value">
            <Fields>
                <ext:RecordField Name="Key" />
                <ext:RecordField Name="Value" />
            </Fields>
        </ext:JsonReader>
    </Reader>
</ext:Store>

<ext:ComboBox runat="server" ID="myCombo" StoreID="Store1" 
     DisplayField="Key" ValueField="Value">
</ext:ComboBox>

 

// In SamplePage.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
    var getRegions = new Dictionary<string, string>();
    getRegions.Add("Region1", "England");
    getRegions.Add("Region2", "Scotland");
    getRegions.Add("Region3", "Wales");

    Store1.DataSource = getRegions;
    Store1.DataBind();
}

这会产生一个页面,其中包含一个 Ext.Net 组合框,该组合框显示了三个值。您几乎肯定需要进一步调整它以获得您所追求的(因为我不熟悉您的数据库模式),但它应该为您指明正确的方向。

于 2011-02-17T15:50:26.900 回答
0

http://en.csharp-online.net/DataViews_and_Data_Binding%E2%80%94Single-Value_Binding

于 2011-02-16T08:22:33.813 回答
0

只是出于兴趣,这里有另一个快速<ext:ComboBox>示例,它演示了在不使用<ext:Store>. <asp:DropDownList>基本上与使用和添加 ListItem 对象的技术相同。

例子

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!X.IsAjaxRequest)
        {
            // Add individual Items
            this.ComboBox1.Items.Add(new ListItem("Region1", "England"));
            this.ComboBox1.Items.Add(new ListItem("Region2", "Scotland"));
            this.ComboBox1.Items.Add(new ListItem("Region3", "Wales"));

            // AddRange alternative
            // this.ComboBox1.Items.AddRange(new ListItem[] {
            //     new ListItem("Region1", "England"),
            //     new ListItem("Region2", "Scotland"),
            //     new ListItem("Region3", "Wales")
            // });
        }
    }
</script>

<ext:ComboBox ID="ComboBox1" runat="server" />

干杯!

于 2011-02-18T16:24:04.060 回答