how to add items to a data grid view combo box
Asked
Active
Viewed 3,233 times
1
-
Are you looking to databind, manually (in the designer), or programatically add the items? – lc. Jan 15 '09 at 14:03
-
And while we're at it, do you want each row to have a different collection of items, or are they the same for the entire column? – lc. Jan 15 '09 at 14:17
-
different collection of items – Jan 15 '09 at 14:29
2 Answers
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.

bruno conde
- 47,767
- 15
- 98
- 117
0
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();
}
}

user500962
- 56
- 3