I am new to asp.net after previously coding in classic asp.

I am needed to do a loop in VB.Net but don't know how to do it.

I need to loop through a data set of 3 records and then place each record in the relevant section on the image below.

http://www.andrewwilliamsportfolio.co.uk/verto/images/news.jpg

How would I loop using VB.net? I know I could use a gridview which would be easy, but then I wouldnt be able to place the text in the right place on the background image.

Any help would be greatly appreciated.

Thanks

To loop through rows in a dataset you could use

For Each dr As DataRow in myDataSet.Rows
  'Do something here
Next

As for "placing each record in the relvant section on the image"... you're going to have to ellaborate a bit more on that one.

P.S. I code in C# so I apologise if my VB is a little rusty

This is the code I have got:

<asp:Formview runat="server" ID="Formview2" DataSourceID="obdsSelectLatestNews">
                                            <ItemTemplate>
<tr><td>
                                                <%# Container.DataItem("news").Replace(Chr(13), "<br />")%> 
</td></tr>
                                            </ItemTemplate>
                                        </asp:Formview>

I want to keep creating a <tr> etc for each record that is returned in the query

I'm not particularly familiar with the FormView control, however from what i've read it is used to ouput a single row at a time, which i believe is not what you want.

Why not use the repeater control? You can bind it to a datasource in the code behind and create an item template as you have with the FormView, but it will create an item for each row in the datasource:

<asp:Repeater ID="rptNews" runat="server"> 
<ItemTemplate> 
<tr><td>  
  <%# Container.DataItem("news").Replace(Chr(13), "<br />")%>
</td></tr> 
</ItemTemplate> 
</asp:Repeater>

I dont know in what form your data is, but a simplified SQL server databinding is as follows:

SqlCommand cmd = new SqlCommand(sqlQuery, sqlConn);  
SqlDataReader rdr = cmd.ExecuteReader();  
rptNews.DataSource = rdr;  
rptNews.DataBind();

Hope that helps.

Thank you for your reply. I am using a SQL server back end, creating the object datasource on the page with the stored procedure in the appcode. Where abouts on that bit of code do I put the object data source Id?

Thanks

Thank you for your help.

I have done it using the following code below.

Thanks for telling me about the Repeater function!

<asp:Repeater DataSourceID="obdsSelectLatestNews" ID="rptNews" runat="server">
                                                <ItemTemplate>
                                                    <tr>
                                                        <td>
                                                             <%# Container.DataItem("news").Replace(Chr(13), "<br />")%> 
                                                        </td>
                                                    </tr> 
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                    </tr>                                              
                                                </ItemTemplate>
                                            </asp:Repeater>

Thank you for your help.

I have done it using the following code below.

Thanks for telling me about the Repeater function!

<asp:Repeater DataSourceID="obdsSelectLatestNews" ID="rptNews" runat="server">
                                                <ItemTemplate>
                                                    <tr>
                                                        <td>
                                                             <%# Container.DataItem("news").Replace(Chr(13), "<br />")%> 
                                                        </td>
                                                    </tr> 
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                    </tr>                                              
                                                </ItemTemplate>
                                            </asp:Repeater>

Sorry for not getting back to you, only checked the thread this morning

Glad I could help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.