【问题标题】:ASP.NET ListView Control: how to style it and retrieve data from database in specific columnsASP.NET ListView 控件:如何设置样式并从特定列中的数据库中检索数据
【发布时间】:2011-10-16 16:37:57
【问题描述】:

我正在尝试使用 ListView 控件显示数据库中的数据列表,如下所示:

员工姓名:xxxxxxxxx ID:111111 职位名称:yyyyyxxxx 组织:uuuuuu

这意味着我想在一个包含 4 列的表中列出数据,其顺序如下: 财产 价值 财产 价值

我修改了这个样式,我成功了。我现在的问题是在两个值列中从数据库中检索数据。我不知道该怎么做。

我的部分代码:

<LayoutTemplate>
    <table border="0" cellpadding="1">
        <tr style="background-color:#003366; color:white">
            <th align="left"> Employee Name </th>
            <td>
            </td>

            <th align="left">ID</th>
            <td></td>
        </tr>

        <tr style="background-color:#003366; color:white"> 
            <th align="left">Job Title.</th>
            <td></td>

            <th align="left">Organization</th>
            <td></td>
        </tr>


        <tr id="itemPlaceholder" runat="server">
        </tr>

    </table>
</LayoutTemplate>

【问题讨论】:

标签: asp.net asp.net-controls


【解决方案1】:
    <LayoutTemplate>
        <table border="0" cellpadding="1">
            <tr style="background-color:#003366; color:white">
                <th align="left"> Employee Name </th>
                <td>
                </td>

                <th align="left">ID</th>
                <td></td>
            </tr>

            <tr style="background-color:#003366; color:white"> 
                <th align="left">Job Title.</th>
                <td></td>

                <th align="left">Organization</th>
                <td></td>
            </tr>
            <asp:PlaceHolder id="itemPlaceholder" runat="server" />

        </table>
    </LayoutTemplate>
    <ItemTemplate>
            <tr style="background-color:#003366; color:white">
                    <td align="left"></td>    
                    <td><%# Eval("EmployeeName")%></td>

                    <td align="left"></td>
                    <td><%# Eval("ID")%></td>
                </tr>

                <tr style="background-color:#003366; color:white"> 
                    <td align="left"></td>
                    <td><%# Eval("JobTitle")</td>

                    <td align="left"></td>
                    <td><%# Eval("Organization")</td>
                </tr>
    </ItemTemplate>

Eval 语句取决于您的数据源

【讨论】:

    猜你喜欢
    • 2013-04-21
    • 1970-01-01
    • 2013-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-13
    • 2011-02-07
    相关资源
    最近更新 更多