Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I need to assign the text value of labelbox in client side.The code is pasted below.

XML
<% For Each one_document As Object In FileRepository.GetAllDocuments()
            %>
             <tr>
                 <td>
                     <%= one_document %>
                     <asp:Label ID="Label4" runat="server" Text="<%# one_document %>"></asp:Label>
                 </td>
             </tr>

           <% Next%>


I need to get the one_document string value in the label box.

Please help
Posted

1 solution

XML
Seriously, this is a terrible way to code - you will never progress anywhere useful going about things this way.  This "spaghetti code" - mixing HTML with server side code - goes completely against what ASP.NET is about.

If you haven't got it, you can download free versions of Visual Studio from the Microsoft website. Learn to use it (and .NET) properly, and you'll find programming much more enjoyable and even easier too.

In your case here, you'd use a Repeater control - something like:

<pre>  <HeaderTemplate><table></HeaderTemplate>
  <ItemTemplate>
      <tr>
         <td><asp:Literal runat="server" ID="litX"></asp:Literal></td>
      </tr>
  </ItemTemplate>
  <FooterTemplate></table></FooterTemplate>


Then in the code behind, perhaps in Page_Load or a button Click event, you have your For...Next loop

VB
For Each one_document As Object In FileRepository.GetAllDocuments()
 ...
Next


and in that assign the values you want to some kind of datasource - a collection, maybe, and DataBind that to the repeater.

Finally, in the repeater's ItemDataBound event, you set the value of litX accordingly.
 
Share this answer
 

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