【发布时间】:2018-05-30 20:02:45
【问题描述】:
我知道这个主题已经讨论了很多,但我找不到解决我的问题的方法。
我已尝试使用 SqlDataSource 使用以下指南创建字段绑定,但我遵循每一步,然后最后字段绑定选项显示为灰色。 https://msdn.microsoft.com/en-us/library/ms178294.aspx
所以我开始尝试将 DropDownList 编码到 GridView 中,但我目前没有在 DDL 中生成任何数据。不知道接下来要添加什么。
下面是我的 GridView 代码,我试图让 ddlCategory 显示我的类别表中的所有类别。
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="FileID" DataSourceID="filenameTableDataSource"
EnableModelValidation="True" Style="text-align: center">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="FileID" HeaderText="FileID" InsertVisible="False" ReadOnly="True" SortExpression="FileID" />
<asp:BoundField DataField="Filename" HeaderText="Filename" SortExpression="Filename" />
<asp:TemplateField HeaderText="Category" SortExpression="Category">
<ItemTemplate>
<asp:Label ID="Category" runat="server" Visible="false" />
<asp:DropDownList ID="ddlCategory" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:BoundField DataField="Category" HeaderText="Category" SortExpression="Category" />--%>
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:CheckBoxField DataField="IsPublished" HeaderText="IsPublished" SortExpression="IsPublished" />
<asp:CheckBoxField DataField="IsArchived" HeaderText="IsArchived" SortExpression="IsArchived" />
</Columns>
</asp:GridView>
这是我用来获取 GridView 数据的 SQL 语句:
SELECT Files.FileID, Files.CategoryID, Files.Filename, Files.Description,
Files.IsPublished, Files.IsArchived, Categories.Description AS Category
FROM Files INNER JOIN Categories ON Files.CategoryID = Categories.CategoryID
提前致谢!
【问题讨论】: