详细信息视图中的下拉列表,未列出项目

发布于 2025-01-05 17:25:43 字数 1269 浏览 1 评论 0原文

大家好

我有一个详细信息视图,其中有 3 个绑定字段和一个模板字段。

模板字段有一个 DropDownList,我已将其连接到 AccessDataSource。

但是当我运行时,下拉列表只有 "System.Data.DataRowView" 作为项目。

我希望将数据库中的项目列在 DropDownList

这是我的代码

asp:TemplateField HeaderText="State/Province" SortExpression="State/Province">
                            <EditItemTemplate>
                                <asp:DropDownList ID="ddlState" runat="server" DataSourceID="AccessDataSource1" 
                                    onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                                </asp:DropDownList>
                                <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
                                    DataFile="~/App_Data/db1.mdb" 
                                    SelectCommand="SELECT [State/Province_name] FROM [State/Province_List ]">
                                </asp:AccessDataSource>
                            </EditItemTemplate>
                        </asp:TemplateField>

我应该为 DropDownList 添加“DataBinding”或“DataBound”事件吗?使其完美?

帮我解决这个问题

谢谢, 阿琼

Hello Everyone

I have a detailsview, where there are 3 bound fields and a template field.

The template field has a DropDownList, which I have connected to an AccessDataSource.

But when I run, the dropdownlist has just the "System.Data.DataRowView" as it's items.

I wish to get the items from DB to be listed down in DropDownList

This is my code

asp:TemplateField HeaderText="State/Province" SortExpression="State/Province">
                            <EditItemTemplate>
                                <asp:DropDownList ID="ddlState" runat="server" DataSourceID="AccessDataSource1" 
                                    onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                                </asp:DropDownList>
                                <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
                                    DataFile="~/App_Data/db1.mdb" 
                                    SelectCommand="SELECT [State/Province_name] FROM [State/Province_List ]">
                                </asp:AccessDataSource>
                            </EditItemTemplate>
                        </asp:TemplateField>

Should I add "DataBinding" or "DataBound" event for DropDownList?? to make it perfect?

Help me regarding this issue

Thanks,
Arjun

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青瓷清茶倾城歌 2025-01-12 17:25:43

定义要在下拉列表中使用的字段

<asp:DropDownList ID="ddlState" runat="server"
   DataSourceID="AccessDataSource1"
   DataTextField="State/Province_name"
   DataValueField="State/Province_name"
   OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>

如果您对此非标准列名称有问题,请尝试使用别名

SELECT [State/Province_name] AS StateProv FROM [State/Province_List ]

[State/Province_List ] 中的空格可以吗?)

然后使用此名称一

<asp:DropDownList ID="ddlState" runat="server"
   DataSourceID="AccessDataSource1"
   DataTextField="StateProv"
   DataValueField="StateProv"
   OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>

Define the filed to use in the drop down list

<asp:DropDownList ID="ddlState" runat="server"
   DataSourceID="AccessDataSource1"
   DataTextField="State/Province_name"
   DataValueField="State/Province_name"
   OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>

If you have problems with this non-standard column name, try to use an alias

SELECT [State/Province_name] AS StateProv FROM [State/Province_List ]

(Is the space in [State/Province_List ] OK?)

Then use this one

<asp:DropDownList ID="ddlState" runat="server"
   DataSourceID="AccessDataSource1"
   DataTextField="StateProv"
   DataValueField="StateProv"
   OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文