简体   繁体   English

具有动态行数的动态GridView

[英]dynamic GridView with dynamic Number Of Row

How I can create dynamic GridView with dynamic number of row When click on button 单击按钮时如何创建具有动态行数的动态GridView

and put in one column DropDownList . 并放入一列DropDownList。

GridView is a databound control. GridView是一个数据绑定控件。 It means that it shows what is in the datasource. 这意味着它显示了数据源中的内容。 To add a row, you need to add an item to the datasource and re-bind the gridview. 要添加一行,您需要向数据源添加一个项目并重新绑定gridview。 You can't add rows to the gridview directly. 您不能直接向gridview添加行。

Your question is pretty brief, but if if i think i understand what you want to do, you could try this: 您的问题很简短,但是如果我认为我了解您想要做什么,则可以尝试以下操作:

in the codebehind of your button 在按钮后面的代码中

List<string> ThisIsYourList = new List<string>();
Gridview1.DataSource = ThisIsYourList;
Gridview1.DataBind();

if you want to add a dropdownlist to every row, you need to add an itemtemplate to your gridview like this: 如果要向每行添加一个下拉列表,则需要向网格视图中添加一个项目模板,如下所示:

   <asp:TemplateField>
   <ItemTemplate>
   <asp:DropDownList ID="DropDownList1" runat="server"/>
   </ItemTemplate>
   </asp:TemplateField>

You add this itemtemplate anywhere between the tags of your gridview. 您可以在gridview的标签之间的任何位置添加此itemtemplate。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM