日期:2014-05-18  浏览次数:20580 次

gridview如何增加空行?
在GridView中,添加一个空的行,然后让用户输入数据,最后保存。
请问,如何实现?

------解决方案--------------------
动态地控制数据源datatable
新增一个空记录


------解决方案--------------------
Grid不是要绑定DataTable吗,在DataTable里AddNew一个新行就好了。
------解决方案--------------------
可以动态添加Footer
单击添加就把GridView的ShowFooter属性设置为true。
单击保存就把GridView的ShowFooter属性设置为false。
效果很不错,LZ试试~~
------解决方案--------------------
看2楼的回答
http://topic.csdn.net/u/20081207/14/65a7da2e-9255-43cc-b819-75bc67e4d753.html
------解决方案--------------------
http://topic.csdn.net/u/20081207/14/65a7da2e-9255-43cc-b819-75bc67e4d753.html
------解决方案--------------------
DataSet ds;
DataRow dr = ds.Tables[0].NewRow();
dr[0] = System.Int32.Parse("0");
dr[1] = "";
dr[2] = "";
ds.Tables[0].Rows.InsertAt(dr, 0);

Gridview1.DataSource = ds;
Gridview1.DataBind();
------解决方案--------------------
http://www.cnblogs.com/lgzh3/archive/2008/10/23/1318119.html
------解决方案--------------------
<table width="96%" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr >
<td width="100%" height="40"><asp:Button ID="btnAdd" runat="server" Text=" 增加通知人" OnClick="add_Click" SkinID="btn_add_4" /></td>
</tr>
<tr>
<td width="100%"><asp:DataGrid ID="DataGrid" runat="server" CssClass="tb_style" Width="100%" DataKeyField="SetDetailID" OnDeleteCommand="DataGrid_Delete" OnEditCommand="DataGrid_Edit" OnUpdateCommand="DataGrid_Update" OnCancelCommand="DataGrid_Cancel" AllowSorting="true" AutoGenerateColumns="false" OnItemDataBound="DataGrid_ItemDataBound" >
<HeaderStyle CssClass="tb_title" Font-Bold="true" />

<Columns>
<asp:BoundColumn ReadOnly="True" HeaderText="序号" ItemStyle-Width="6%" HeaderStyle-Font-Bold="true" />
<asp:TemplateColumn HeaderText="通知人" ItemStyle-Width="13%" HeaderStyle-Font-Bold="true" >
<ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "NoticeMan")%> </ItemTemplate>
<EditItemTemplate>
<cc1:DropDownListExtend ID="DropDownListExtend1" MaxLength="20" runat="server"></cc1:DropDownListExtend>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="所属单位" ItemStyle-Width="28%" HeaderStyle-Font-Bold="true" >
<ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "UnitName")%> </ItemTemplate>
<EditItemTemplate>
<asp:TextBox Width="215" ID="txtUnitName" MaxLength="50" Text='<%# DataBinder.Eval(Container.DataItem,"UnitName") %>'