感谢您使用微软产品。BoundColumn 控件不是唯一可以在 DataGrid 的 Columns 集合中设置的控件。还可以指定 TemplateColumn,它使您可以完全控制列的内容。模板的内容可以是任意的;在 DataGrid 的列中可以呈现任何内容,包括服务器控件。下面的示例代码说明如何使用 TemplateColumn 控件将“State”列呈现为下拉列表。
<asp:TemplateColumn HeaderText="state">
<ItemTemplate>
   <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "state") %>'/>
</ItemTemplate>
<EditItemTemplate>
     <asp:DropDownList runat="server" id="edit_State">
           <asp:ListItem>CA</asp:ListItem>
           <asp:ListItem>IN</asp:ListItem>
           <asp:ListItem>KS</asp:ListItem>
           <asp:ListItem>MD</asp:ListItem>
           <asp:ListItem>MI</asp:ListItem>
           <asp:ListItem>OR</asp:ListItem>
           <asp:ListItem>TN</asp:ListItem>
           <asp:ListItem>UT</asp:ListItem>
      </asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>注意,在使用DropDownList的编辑过程中,需要使下拉列表行中的数据状态反映出数据记录中该字段的值。您可采用Hashtable()和设置DropDownList控件的SelectedIndex属性来实现。关于该示例的完整实现,请参考微软官方网站:
http://www.gotdotnet.com/quickstart/aspplus/samples/webforms/data/VB/datagrid8.aspx
该示例的完整源代码,请参考微软官方网站:
http://www.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/data/datagrid8.src
 — 微软全球技术中心 VB支持中心本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。