如何在c#中向DataGridViewRow添加ComboBox?

时间:2012-02-14 06:07:10

标签: c# windows datagridview

我正在使用代码

DataGridViewRow dViewRow = new DataGridViewRow();    
DataGridViewTextBoxCell Sno = new DataGridViewTextBoxCell();    
DataGridViewComboBoxCell dgCombo = new DataGridViewComboBoxCell();

dViewRow.Cells.Add(Sno);
dViewRow.Cells.Add(dgCombo);
dViewRow.Cells[0].Value = 1;
dViewRow.Cells[1].Value = "ASP";

然后我使用DataGridViewRow

DataGrid绑定到主gridViewProducts.Rows.Add(dViewRow);

但是我收到以下错误:

System.ArgumentException:DatagridviewCombobox值无效

1 个答案:

答案 0 :(得分:-1)

用户TemplateField

<asp:TemplateField HeaderText="List">
                    <ItemTemplate>
                       <asp:DropDownList ID="dlBox" runat="server"></asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>