grid view combobox

随声附和 提交于 2019-12-11 07:49:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!