如何在网格视图中添加空行?

时间:2022-09-07 09:16:33

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

我是ASP.NET的新手,我将一个数据对象列表绑定到网格视图。我想在网格视图中的每个记录后显示空白行,所以我在后面的代码中通过如下方式完成此操作

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();

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.

它工作正确我在网格视图中得到所需的空白行,但我知道这是不正确的方式,因为我正在添加对象到列表所以我可以添加空行代替我非常想调整此空白从aspx页面开始。我知道有另一种使用DataTable的方法,但它也不是很好,因为它还将不必要的记录添加到DataTable。所以任何其他工作或解决方法都会非常好。谢谢。

3 个解决方案

#1


1  

Try This

尝试这个

<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>

#2


0  

You can't have an empty row in the Datagrid if it isn't present in the data source. You have to think that after all the grid data is just a representation of your data source, if there is a empty row, the grid will show it, if there is not, it wont.

如果数据源中不存在空行,则数据网格中不能有空行。您必须认为,在所有网格数据只是数据源的表示之后,如果存在空行,则网格将显示它,如果没有,则不会。

#3


0  

Write a stored procedure to get Output Parameter from sql server and bind to grid view if record is not there..

编写存储过程以从sql server获取输出参数,如果没有记录,则绑定到网格视图。

#1


1  

Try This

尝试这个

<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>

#2


0  

You can't have an empty row in the Datagrid if it isn't present in the data source. You have to think that after all the grid data is just a representation of your data source, if there is a empty row, the grid will show it, if there is not, it wont.

如果数据源中不存在空行,则数据网格中不能有空行。您必须认为,在所有网格数据只是数据源的表示之后,如果存在空行,则网格将显示它,如果没有,则不会。

#3


0  

Write a stored procedure to get Output Parameter from sql server and bind to grid view if record is not there..

编写存储过程以从sql server获取输出参数,如果没有记录,则绑定到网格视图。