在C#中的GridView中将单个数据库行分为2行 [英] Single Database row into 2 rows in gridview in c#

查看:95
本文介绍了在C#中的GridView中将单个数据库行分为2行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从db中连续获取总共10列...

我想在gridvew的一行中显示5列,在另一行中显示其他5列..

我有多行返回frm db ..

怎么办???

我正在创建Web应用.

i m getting total 10 columns in a row from db...

i want to show 5 columns in one row n other 5 in another row in gridvew..

i m having multiple rows returned frm db..

how to do???

i m creating web app.

推荐答案

此行为是典型的列表视图.
您可以使用以下列表视图来解决:
This behavior is typical of a listview.
You can solve using a listview like this:
<h3>
    ListView split row</h3>
<asp:listview id="ListView2" datasourceid="SqlDataSource2" xmlns:asp="#unknown">
    ItemPlaceholderID="ContactItemContainer" runat="server">
    <layouttemplate>
        <table cellpadding="4" width="640px" runat="server" id="tblContacts">
            <tr id="Tr1" runat="server">
                <th id="Th1" colspan="3" runat="server">
                    Contacts
                </th>
            </tr>
            <tr runat="server" id="ContactItemContainer" />
        </table>
        <asp:datapager id="ContactsDataPager" runat="server" pagesize="30">
            <fields>
                <asp:numericpagerfield buttoncount="10" />
            </fields>
        </asp:datapager>
    </layouttemplate>
    <itemtemplate>
        <tr>
            <td id="Td8" class="item" runat="server">
                <asp:label id="Label2" runat="server" text="<%# Eval("TitleOfCourtesy") %>" />
            </td>
            <td id="Td5" class="item" runat="server">
                <asp:label id="NameLabel" runat="server" text="<%# Eval("LastName") %>" />
            </td>
            <td id="Td7" class="item" runat="server">
                <asp:label id="Label1" runat="server" text="<%# Eval("FirstName") %>" />
            </td>
        </tr><tr>
            <td id="Td9" class="item" runat="server">
                <asp:label id="Label3" runat="server" text="<%# Eval("Title") %>" />
            </td>
            <td id="Td10" class="item" runat="server">
                <asp:label id="Label4" runat="server" text="<%# Eval("City") %>" />
            </td>
            <td id="Td11" class="item" runat="server">
                <asp:label id="Label5" runat="server" text="<%# Eval("Country") %>" />
            </td>
        </tr>
    </itemtemplate>
    <itemseparatortemplate>
        <tr style="height:1px;">
        <td colspan="3" style="border-top: 1px solid #00C0C0; height:1px;">
            
        </td>
        </tr>
    </itemseparatortemplate>
</asp:listview>
<asp:sqldatasource id="SqlDataSource2" runat="server" connectionstring="<%


ConnectionStrings:Northwind%>" xmlns:asp =" #unknown" /asp:sqldatasource >
ConnectionStrings:Northwind %>" xmlns:asp="#unknown"> SelectCommand="SELECT [FirstName], [LastName] , [Title], [TitleOfCourtesy], [City], [Country] FROM Employees ORDER BY [LastName], [FirstName] "></asp:sqldatasource>


这篇关于在C#中的GridView中将单个数据库行分为2行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆