views:

59

answers:

3

Hi,

I was wondering if there is an existing control that I could use to achieve what I am trying.

Basically, I have a html table that I display my header information.

It looks something like this:

<table class="tableEdit">
    <tr>
        <th>Job ID</th><td>10</td>
        <th>Client</th><td>Tom</td>
    </tr>
    <tr>
        <th>Comments</th><td>Comments are here</td>
    </tr>
</table>  

I am wondering if there is an existing control that I can use as a container. Then I can assign the datasource to that control and leverage the field values as such.

<asp:Somecontrol runat="server" ID="someid">

<table class="tableEdit">
    <tr>
        <th>Job ID</th><td><%# Eval("Id") %></td>
        <th>Client</th><td><%# Eval("Client.Name") %></td>
    </tr>
    <tr>
        <th>Comments</th><td><%# Eval("Comments") %></td>
    </tr>
</table> 

</asp:Somecontrol>

private void BindHeader()
{
 SomeObjectType data = DAL.SomeMethod();
 someid.Datasource = data;
 someid.DataBind();
}

Is there anything out there to do this? I want to be able to control the layout of the fields within the container.

Thanks.

A: 

Use the GridView control. You can attach CSS classes to many properties in Design mode for controlling the layout.

HardCode
Sorry, I probably should not have used a table for the example. To clear the layout could very well be flow layout, random, anything.I just want a region to be contained by a single datasource and I can use evals to bind the fields were I see fit. Hope my question is getting clearer. Thanks.
minalg
A: 

for asp.net 2.0

<asp:Repeater runat="server" id="someid">
        <ItemTemplate>
    <table class="tableEdit">
        <tr>
            <th>Job ID</th><td><%# Eval("Id") %></td>
            <th>Client</th><td><%# Eval("Client.Name") %></td>
        </tr>
        <tr>
            <th>Comments</th><td><%# Eval("Comments") %></td>
        </tr>
    </table>
        </ItemTemplate>
</asp:Repeater>

you can use the control in asp.net 3.5, but i won't attempt the syntax off the cuff since I don't get to use 3.5 on a daily basis.

Al W
This wasn't exactly what I was after, but it does most of what I need. Thanks.
minalg
+1  A: 

Actually what i was after was the FormView control.

I had never used this control previously, but this is the exact control for what i wanted to do.

It allows to to mark a region, assign a datasource and bind items as desired.

   <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource2" Visible="false">
                    <ItemTemplate>
                        <table style="border-collapse: collapse;" class="tableEdit">
                            <tr>
                                <td>ClientId</td>
                                <td><asp:Label ID="ClientId" runat="server" Text='<%# Eval("ClientId") %>' /></td>
                            </tr>
                            <tr>
                                <td>ClientCode</td>
                                <td><asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("ClientCode") %>' /></td>
                            </tr>
                            <tr>
                                <td>Name</td>
                                <td><asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("Name") %>' /></td>
                            </tr>
                            <tr>
                                <td>BillingContactName</td>
                                <td><asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("BillingContactName") %>' /></td>
                            </tr>

Thanks AI W for your input. Repeater is also suitable but for binding "a" record, FormView is ideal i think. Thanks.

minalg