感謝您的答案傢伙。它看起來像定製DataGrid是要走的路。對於任何ASP.NET新手,這裏是我在做什麼
<asp:DataGrid ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="RuleID" Visible="False" HeaderText="RuleID"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Category">
<ItemTemplate>
<!-- in case we want to display an image -->
<asp:Literal ID="litImage" runat="server">
</asp:Literal>
<asp:DropDownList ID="categoryListDropdown" runat="server"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
這將創建一個數據網格。然後,我們可以將其綁定到數據源(在我的情況數據表),並使用之類的東西
foreach (DataGridItem item in this.GridView1.Items)
{
DropDownList categoryListDropdown = ((DropDownList)item.FindControl("categoryListDropdown"));
categoryListDropdown.Items.AddRange(listItems.ToArray());
}
來填充數據網格的INTIAL下拉。在這種情況下,您還可以訪問item.Cells [0] .text以獲取RuleID。
我自己的注意事項:ASP.NET模型執行代碼隱藏文件中的所有內容。在高層次上,您始終可以遍歷GridView1。獲取每一行的項目,以及item.findControl(「ControlID」)來查詢存儲在每個項目中的值,例如在按下「更新」按鈕之後。