Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have prepared a set of objects, which are meant to contain data as objects, and, I am trying to figure out how to use LINQ to retrieve a relatively hierarchical organization of data objects, through ASP.NET.

My first attempt uses a var which reads a ContactDetails object, however, I realize that I cannot use this var outside of the page where I can write code, whilst I would like to retrieve the data through the asp.net controls.

Can anyone guide me and provide me with an example, because I feel a bit lost?

C#
CustomerManagement.aspx.cs
protected void Page_Load(object sender, EventArgs e)
    {
        var query = from ContactDetail contactdetail in ContactDetail.ContactDetails
                    select contactdetail;
    }


CustomerManagement.aspx
HTML
<ajaxToolkit:TabPanel ID="TabPanel2"  runat="server" 
                HeaderText="Customer Details">
                <HeaderTemplate>
                    Customer Details
                </HeaderTemplate>
                <ContentTemplate><br />Name: 
                    <asp:TextBox ID="txtName" runat="server" style="margin-left: 18px" 
                        Width="175px">John</asp:TextBox>
                    Surname:
                    <asp:TextBox ID="txtSurname" runat="server" Width="154px">Doe</asp:TextBox>
                    <br />
                    Address:
                    <asp:TextBox ID="txtAddressLine1" runat="server" Width="406px">123 Maverick Heights</asp:TextBox>
                    <asp:TextBox ID="txtAddressLine2" runat="server" Width="470px"></asp:TextBox>
                    <asp:TextBox ID="txtAddressLine3" runat="server" Width="470px">Arkansas</asp:TextBox>
                    <br />
                    <br />
                    Subscription Start: 01/01/2013 Subscription Expiry: 
                    31/12/2016<br />


I have noticed that the textbox control does not seem to have a data source, so I am hoping a better control is available for use to query an object oriented data model, otherwise I will require opening a connection to a Jet Engine database, however, our tutor discouraged us from using both structured and object oriented programming so I am sticking to the use of data within objects, as a similar model seems to have been adopted when Microsoft Office was designed.
Posted
Updated 30-Dec-13 4:05am
v2
Comments
Amey K Bhatkar 30-Dec-13 13:30pm    
What is ContactDetail??

1 solution

You can use any of the Data listing control such as Repeater , DetailView etc. to bind the Linq object results to the Datasource of it. It gives you much more easy way to define the layout/design to display data rather than just using label or literals.

Or still you can use the query like below and use the object anywhere to assign to the display controls

C#
(from ContactDetail contactdetail in ContactDetail.ContactDetails
                            select new ModelClass
                            {
                                ModelClassProperty1 = contactdetail.Property1,
                                ModelClassProperty2 = contactdetail.Property2,
                            }).FirstOrDefault();

//Should change the property class names as its just given for understanding.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900