如何添加网格视图空白行? [英] How to add blank row in grid view?
问题描述
我是新来的ASP.NET我正在数据对象的一个列表绑定到网格视图。我想在网格视图中的每个记录后显示空白行,所以我必须在code做到了这一点通过如下背后
I am new to the ASP.NET i am binding one list of data object to the grid view. I want to display blank row after each record in grid view so i have done this by as below in code behind
List<DatabaseDTO> lstdatabase= new List<DatabaseDTO>();
foreach(int jobNumber in JobnumberList)
{
DatabaseDTO dataObject = new DatabaseDTO();
dataobject = GetDatabaseData(jobNumber);//Method to retrieve data and return data object
lstdatabase.Add(dataObject);
lstdatabase.Add(new DatabaseDTO());
}
gridView.DataSource = lstdatabase;
gridView.DataBind();
它的工作正确的我得到所需的空白行网格中的观点,但我知道这是不是因为我加入对象列表中,这样我就可以代替,我会非常喜欢添加空白行正道调整从aspx页面这个空行。我知道有使用数据表
另一种方式,但它也不是非常好,因为它也增加了不必要的记录到数据表
。因此,任何其他变通或办法来解决,这将是非常大的。谢谢。
it's working correct i am getting the desired blank row in the grid view but i know this is not right way because i am adding object to the list so i can add the blank row in place of that i would very much like to adjust this blank row from the aspx page. I know there is another way using the DataTable
but it is also not very good because it also adds the unnecessary records to the DataTable
. So any other work around or way to solve this would be very great. Thank you.
推荐答案
试试这个
<div>
<asp:DataList ID="DataList1" runat="server">
<ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
<HeaderTemplate>
<table width="900px">
<tr>
<td width="300px">
<b>Name</b>
</td>
<td width="300px">
<b>Account No</b>
</td>
<td width="300px">
<b>Company</b>
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table width="900px">
<tr>
<td align="left" width="300px">
<%# DataBinder.Eval(Container.DataItem, "Name")%>
</td>
<td align="left" width="300px">
<%# DataBinder.Eval(Container.DataItem, "AccountNo")%>
</td>
<td align="left" width="300px">
<%# DataBinder.Eval(Container.DataItem, "Company")%>
</td>
</tr>
<tr>
<td align="left" width="300px">
<br />
</td>
<td align="left" width="300px">
<br />
</td>
<td align="left" width="300px">
<br />
</td>
</tr>
</table>
</ItemTemplate>
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
<SeparatorTemplate><br /></SeparatorTemplate>
</asp:DataList>
</div>
这篇关于如何添加网格视图空白行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!