?
Solved

do while loop in a table grid

Posted on 2006-06-03
4
Medium Priority
?
730 Views
Last Modified: 2007-12-19
What am I doing wrong here? I'm trying to get the table rows to repeat, but it's not working. Can anyone help?

<%@ Import Namespace="System.Data" %>
<%@ Page Language="VB" %>

<HTML>
  <HEAD>
<script language="vb" runat="server">

 Sub Page_Load()
     MyGrid.DataSource = CreateData()
     MyGrid.DataBind()
  End Sub
  Function CreateData() As ICollection
    Dim dt As New DataTable()
    Dim dr As DataRow
    Dim i as Integer = 1

      dt.Columns.Add(New DataColumn("Display List", GetType(Integer)))
        
       Do While i <= 5
            'Add a row
            dr = dt.NewRow()            
            dr(0)= i
            i = i + 1
        Loop
   

     Dim dv As New DataView(dt)
     Return dv
   End Function
   
</script>
</HEAD>
<body>

<p>Do While...Loop in a table I hope:</p><br><br>

<table>      
<tr>
 <td colspan="3">
                  <asp:label
                  id="title"
                  text="Amortization Table"
                  runat="server">
                  </asp:label>
                  
                  <asp:datagrid
                  id="MyGrid"
                  autogeneratecolumns="True"
                  runat="server">
                  </asp:datagrid>
            </td>
            </tr>
</table>

<p>This is the do loop not in the table </p>
<%
Dim i as Integer = 1
Do While i <= 5
%>
   <font size="<%=i%>">Welcome to ASP.NET</font><br>
<%
   i = i + 1
Loop
%>


</body>
</HTML>

Any help will be appreciated.

thanks

0
Comment
Question by:nflowers1228
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
Sam_Jayander earned 2000 total points
ID: 16823978
Hi,

The problem is, you have created  a datarow-dr(which belongs to datatable-dt) and also assigned the value. But you have not added it to the datatable.

so insert this line in your do loop.

Do While i <= 5
          'Add a row
          dr = dt.NewRow()            
          dr(0)= i
          dt.Rows.Add(dr)     ----------> new line to be added.
          i = i + 1
Loop

Hope this will solve your problem.

Regards,
--Sam.
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 16826266
why don't u use a datagrid and bind it to ur datasoure?. .. there is no need for all those loops and just requires 2-3 lines of code

Rejo
0
 

Author Comment

by:nflowers1228
ID: 16827025
Thanks Sam_Jayander! that seems to be doing the trick!
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 16840275
am sorry .. should read the question more carefully :-( .. seems like u were indeed using a datagrid and just building a datatable from scrath ..
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question