Dane Marshall

Dane Marshall

  • NA
  • 6
  • 3.9k

C# .Net Looping

Oct 10 2011 4:35 AM
Hi,

I am a little stuck on how to achieve the following.

What I want to do is loop through some information in the database via Linq to SQL and display the looped information. In my example the query would bring back two sets of results, therefore I would like it to display both sets of information.

In the code behind I have...

  protected void Page_Load(object sender, EventArgs e)
  {
   Partner_References();
  }

  protected void Partner_References()
  {
   var UserVar = HttpContext.Current.Items["UserInfo"] as UserInfo;

   DCDataContext dc = new DCDataContext();

   var PartnerRef = from p in dc.CS_Partnership_References where p.Partner_DNNUserID == UserVar.UserID select p;

   foreach (var pr in PartnerRef)
   {
    Reference_ClientName.Text = pr.Reference_ClientName;
    Reference_ClientName.ID = "Reference_ClientName_" + pr.Reference_ID + "";
    Reference_Content.Text = pr.Reference_Content;
    Reference_Content.ID = "Reference_Content_" + pr.Reference_ID + "";
    Reference_WebsiteImage.Text = pr.Reference_WebsiteImage;
    Reference_WebsiteImage.ID = "Reference_WebsiteImage_" + pr.Reference_ID + "";
    Reference_WebsiteURL.Text = pr.Reference_WebsiteURL;
    Reference_WebsiteURL.ID = "Reference_WebsiteURL_" + pr.Reference_ID + "";
   }
  }

In the front end .ascx I have...

<div class="PartnerDetails_Info">
 <span class="Title">Reference Client Name:</span>
 <span class="Input"><asp:TextBox ID="Reference_ClientName" runat="server" /></span>
 <span class="Title">Reference Website URL:</span>
 <span class="Input"><asp:TextBox ID="Reference_WebsiteURL" runat="server" /></span>
 <span class="Title">Reference Content:</span>
 <span class="Input"><asp:TextBox ID="Reference_Content" runat="server" /></span>
 <span class="Title">Reference Website Image:</span>
 <span class="Input"><asp:TextBox ID="Reference_WebsiteImage" runat="server" /></span>
</div>
<span class="Line_Break"></span>

No my question is, how would I display both the results in the front end .ascx, with the ID's of the TextBox's changing based on the Reference_ID.

This is working fine bringing back the last result but how would I get it to display both like below?

<div class="PartnerDetails_Info">
 <span class="Title">Reference Client Name:</span>
 <span class="Input"><asp:TextBox ID="Reference_ClientName_1" runat="server" /></span>
 <span class="Title">Reference Website URL:</span>
 <span class="Input"><asp:TextBox ID="Reference_WebsiteURL_1" runat="server" /></span>
 <span class="Title">Reference Content:</span>
 <span class="Input"><asp:TextBox ID="Reference_Content_1" runat="server" /></span>
 <span class="Title">Reference Website Image:</span>
 <span class="Input"><asp:TextBox ID="Reference_WebsiteImage_1" runat="server" /></span>
</div>
<span class="Line_Break"></span>
<div class="PartnerDetails_Info">
 <span class="Title">Reference Client Name:</span>
 <span class="Input"><asp:TextBox ID="Reference_ClientName_2" runat="server" /></span>
 <span class="Title">Reference Website URL:</span>
 <span class="Input"><asp:TextBox ID="Reference_WebsiteURL_2" runat="server" /></span>
 <span class="Title">Reference Content:</span>
 <span class="Input"><asp:TextBox ID="Reference_Content_2" runat="server" /></span>
 <span class="Title">Reference Website Image:</span>
 <span class="Input"><asp:TextBox ID="Reference_WebsiteImage_2" runat="server" /></span>
</div>
<span class="Line_Break"></span>

Many thanks,

Dane


Answers (3)