问题
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();
}
}
来源:https://stackoverflow.com/questions/446825/grid-view-combobox