0

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

3
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by crishjeny
0

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

0

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

0

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.

0

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

0

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>
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.