how to add items to a data grid view combo box
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You have a very good example here. Basically, the combobox is created and populated independently from the data binding.
This is a very generic question. If you're having more specific problems please let us know.
回答2:
First add ad dropdownlist to your gridview with a template field like this Make sure you add an OnRowCreated Event to your gridview
<asp:GridView ID="GridView1" runat="server" OnRowCreated="GridView1_RowCreated">
<Columns>
<asp:TemplateField HeaderText="Prerequisite Course">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:DropDownList ID="ddlPrerequisiteCourseCode" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Next in code behind Add a GridView1_RowCreated Event to your GridView
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Bind drop down to PrerequisiteCourseCodes
DropDownList ddl = (DropDownList)e.Row.FindControl("ddlPrerequisiteCourseCode");
ddl.DataSource = PrerequisiteCourseCodeList;
ddl.DataBind();
}
}