2012-12-07 102 views
0

我有一个gridview连接到sqldatasource,我的select语句连接两个表,Survey &类别。 Survey中的一列是Cateogry_ID,它是指类别表“ID”的主键。我创建的连接是显示类别名称而不是ID。如何绑定GridView的编辑模板中的下拉列表

SELECT 
S.[ID], 
S.[Survey_Name], 
S.[Start_Date], 
S.[End_Date], 
C.[Category_Name], 
S.[Username], 
S.[Picture], 
S.[Audience] 
FROM [Survey] S 
Inner Join 
Category C On S.Category_ID = C.ID 
时,管理员想要更新调查表,想要更新类别

,我只希望他从category_name列的名字从挑表category ..我怎样才能在编辑绑定一个下拉列表该列的模板,并在设计时间实现这一点?

回答

1

这里有一个在sql中将表格列绑定到gridview的工作示例。 how-to-bind-a-dropdownlist-with-a-edititemtemplate-in-the-gridview在那里使用您的列名实现相同。

有一个

<EditItemTemplate> 
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDistinctDS" 
DataTextField="state" DataValueField="state" SelectedValue='<%# Bind("your column name") %>' > 
</asp:DropDownList> 
</EditItemTemplate> 
+0

谢谢,这工作。但是为这个下拉框添加一个sqldatasource是错误的吗?或者可以添加尽可能多的我想要的? – BasharKH

相关问题