Looping through a session array and displaying items in vb.net

Last post 04-25-2009 1:59 PM by rtpHarry. 5 replies.

Sort Posts:

  • Looping through a session array and displaying items in vb.net

    04-24-2009, 10:51 AM
    • Member
      12 point Member
    • penkye
    • Member since 03-11-2009, 1:33 PM
    • Posts 22

    Hi all,

           I'm still new to this concept of asp.net and i'm not sure how to handle this. In pure asp it seems easy but i can't find the equivalent way of doing in asp.net. I am trying to loop through an session array and display the values on the form. However i need to put a value in a textbox control and it's treating it as a string. Can anyone help me so i can make the textbox control "QtyTB" that take the value as a data and not a string. Thanks.

    <table style="width: 100%;">

    <tr style="background-color:Blue; color:#fff; font-weight:bold;">

    <td>Product #</td>

    <td>Quantity</td>

    <td>Price</td>

    <td>Make a choice</td>

    </tr>

    <%

    Dim ar2 As New ArrayList

    Dim i As Integer

    ar2 = Session("prod_i")

     

    Dim ar3 As New ArrayListar3 = Session("price_i")

     

    Dim ar4 As New ArrayList

    ar4 = Session("qty_i")

     

    Dim ar As New ArrayListar = Session("recnum_i")

     

    For i = 0 To ar2.Count - 1

    %>

    <tr>

    <td><% Response.Write(ar2(i))%></td>

    <td><asp:TextBox ID="QtyTB" runat="server" Text='<% Response.Write(ar4(i))%>' Width="25" /></td>

    <td><% Response.Write(ar3(i))%></td>

    <td>&nbsp;</td>

    </tr>

    <%Next%>

    </table>

  • Re: Looping through a session array and displaying items in vb.net

    04-24-2009, 11:10 AM

    How about using: QtyTB.Text = "Whatever string you want"

  • Re: Looping through a session array and displaying items in vb.net

    04-24-2009, 11:10 AM
    Answer
    • All-Star
      35,664 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 8:51 AM
    • Lincoln, England
    • Posts 5,783

    Hey,

    This isnt really the way you should be working with asp.net, this is more of a classic asp technique you have used.

    You have controls such as <asp:Gridview> to generate grids, and you can set the value of QtyTb in the codebehind with some code such as QtyTB.Text="Some value"

    These will get you started:

  • Re: Looping through a session array and displaying items in vb.net

    04-24-2009, 11:19 AM
    • Member
      12 point Member
    • penkye
    • Member since 03-11-2009, 1:33 PM
    • Posts 22

    Hi,

       Thanks for your replies, i can't use a gridview because i can't manipulate the display after i've passed the values to it and i believe only one data source can be passed to a gridview control. Please correct me if i'm wrong. i have a group of session arrays that come into play. The ID.text property may not work because i need to loop through array on the form and not in the page_load event. I do appreciate the suggestion though.

  • Re: Looping through a session array and displaying items in vb.net

    04-24-2009, 11:32 AM
    • Participant
      1,394 point Participant
    • nareshprakash
    • Member since 04-12-2009, 3:25 AM
    • Delhi
    • Posts 284

    recheck your code because u have mistake in your code

    For i = 0 To ar2.Count - 1

    %>

    <tr>

    <td><% Response.Write(ar2(i))%></td>

    <td><asp:TextBox ID="QtyTB" runat="server" Text='<% Response.Write(ar4(i))%>' Width="25" /></td> //here overwrite value in loop so how can u get all value of session. suppose first time u write "a",  and next time u overwrite textbox with another value so how can you get all value in text box. check again... it is working...

    <td><% Response.Write(ar3(i))%></td>

    <td>&nbsp;</td>

    </tr>

    <%Next%>

    </table>

    Thanks
    Naresh Prakash.
    Click Here : SKY IS NOT THE LIMIT

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
  • Re: Looping through a session array and displaying items in vb.net

    04-25-2009, 1:59 PM
    • All-Star
      35,664 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 8:51 AM
    • Lincoln, England
    • Posts 5,783

    penkye:

    Hi,

       Thanks for your replies, i can't use a gridview because i can't manipulate the display after i've passed the values to it and i believe only one data source can be passed to a gridview control. Please correct me if i'm wrong. i have a group of session arrays that come into play. The ID.text property may not work because i need to loop through array on the form and not in the page_load event. I do appreciate the suggestion though.



    If you require more control over the html markup then you can use the newer asp.net 3.5 control <asp:ListView>

    If you need to build your data into a single model then you should use an ObjectDataSource and build what is known as a DAL (data access layer). Then you can plumb it into your databound control by colleciting all the session data into a single data structure and then binding to that.

Page 1 of 1 (6 items)