ASP.NET ListView Control: how to style it and retrieve data from database in specific columns

814 Views Asked by At

I am trying to use the ListView control to show a list of data from the database as following:

Employee Name: xxxxxxxxx ID: 111111 Job Title: yyyyyxxxx Organization: uuuuuu

which means I want to list the data in a table of 4 columns that orders as following: Property Value Property Value

I modified the to get this style and I succeeded. My problem now is to retrieve data from the database in both value columns. I don't know how to do that.

Part of my code:

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

There are 1 best solutions below

0
On BEST ANSWER
    <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>

The Eval statements depend on your datasource