来自DataTable的Ext.NET ComboBox Databind

时间:2014-09-10 09:15:29

标签: c# asp.net data-binding combobox ext.net

我有一个ext.net v2.5组合框,我试图在服务器端数据绑定组合框,使用.net数据加载asocieted商店,但是无效。

任何想法如何做到这一点。数据绑定数据库与组合框?

<ext:ComboBox  ID="ddlProduct" runat="server" ValueField="IDProduct"  DisplayField="ProductName" FieldLabel="Product" LabelWidth="50" Width="250">
                            <Store>
                                <ext:Store runat="server" ID="ddlProductStore">
                                    <Model>
                                        <ext:Model runat="server">
                                            <Fields>
                                                <ext:ModelField Name="IDProduct" />
                                                <ext:ModelField Name="ProductName" />
                                            </Fields>
                                        </ext:Model>
                                    </Model>
                                </ext:Store>
                            </Store>
                        </ext:ComboBox>

服务器端代码:

ddlProductStore.DataSource = MyApp.Data.DataRepository.Provider.ExecuteDataSet("sp_GetSegmentProducts ", 1).Tables(0)
        ddlProductStore.DataBind()

1 个答案:

答案 0 :(得分:2)

在下面的测试中,它似乎与DataTable配合得很好。所以,我认为你身边的DataTable没有要求的列。

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

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!X.IsAjaxRequest)
        {
            DataTable dataTable = new DataTable();

            dataTable.Columns.AddRange(new DataColumn[] {
                new DataColumn("IDProduct"),
                new DataColumn("ProductName")
            });

            dataTable.Rows.Add(new object[] { "id1", "Name1" });
            dataTable.Rows.Add(new object[] { "id2", "Name2" });

            this.ddlProductStore.DataSource = dataTable;
        }
    }
</script>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>Ext.NET v2 Example</title>
</head>
<body>
    <form runat="server">
        <ext:ResourceManager runat="server" />

        <ext:ComboBox 
            runat="server" 
            ValueField="IDProduct" 
            DisplayField="ProductName" 
            FieldLabel="Product" 
            LabelWidth="50" 
            Width="250">
            <Store>
                <ext:Store ID="ddlProductStore" runat="server">
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="IDProduct" />
                                <ext:ModelField Name="ProductName" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
        </ext:ComboBox>
    </form>
</body>
</html>