Results 1 to 11 of 11

Thread: Displaying data... that simple a question

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Displaying data... that simple a question

    There may be something fundamentally wrong with the way I'm thinking.

    I have a dataset, with a couple columns, and a few rows. Now, if I wanted to make an editable form for this (one textbox for each column in each row, thus creating a lot of textboxes), how would I go about doing this?

    From the current mindset I have, which is very ASP 3.0 based, I'd so something like this:

    VB Code:
    1. 'Code behind:
    2.  Response.Write("<table border=1><tr>")
    3.  
    4.         For intColCount = 0 To ds.Tables(0).Columns.Count - 1
    5.  
    6.             Response.Write("<td><b>" & ds.Tables(0).Columns(intColCount).ToString & "</b></td>")
    7.  
    8.         Next
    9.  
    10.         Response.Write("</tr>")
    11.  
    12.  
    13.  
    14.         For intCount = 0 To ds.Tables(0).Rows.Count - 1
    15.             Response.Write("<tr>")
    16.             For intCount2 = 0 To ds.Tables(0).Columns.Count - 1
    17.                 Response.Write("<td>" & ds.Tables(0).Rows(intCount).Item(intCount2).ToString & "</td>")
    18.             Next
    19.             Response.Write("</tr>")
    20.         Next
    21.  
    22.         Response.Write("</table>")

    You can see what I'm doing here, and for editable textboxes, I'd just replace the appropriate <td>s, etc, etc, etc.

    But a few questions arise:

    1) Is this the right way at all?
    2) What if I wished to have the output of this above code in the middle of some page where other elements already exist? Would I place this code inline to the ASPX page contents, or is that wrong?

    Enlighten me.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    I am just learning ASP.NET and I tend to stay away from having to code HTML. What I did was use the DataList control. Basically, add the controls you want to use for a single dataset row in the DataList's Item Template area and then bind the DataList to the Dataset. The DataList_ItemDataBound event will fire for every row in the Dataset allowing you to populate the controls (there are other methods as well). .NET will handle writing the HTML code to duplicate everything in Item Template area for each row in the dataset.

    The concept of DataBinding in .NET seems to be very different than it is in VB. I did use a DataReader and am assuming its the same as using a DataSet. I guess I am also assuming you are using VB.Net for the code behind page....

    So much to learn...

    If you want a live example of the DataList control in action, checkout the Business Directory at mrpmchamber.ca (browse the directory using the list you will see on the left, which is an Infragistics Treeview control).

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    That's interesting. I just played a bit with the datalist control, seems like something I'm looking for.

    Can you post some code you may have written already for this?

    I managed to bind the datalist with the dataset, but wasn't sure how to proceed in the ItemDataBound event.

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Here is a snippet of the procedure used by the business directory page i mentioned.

    VB Code:
    1. Private Sub dlstDirectory_ItemDataBound(ByVal sender As Object, _
    2. ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)  _
    3. Handles dlstDirectory.ItemDataBound
    4.  
    5.          'check if the ItemDataBound event is firing for the
    6.          'Item and/or AlternatingItem rows.  
    7.          'Ignore the Header and Footer events
    8.         If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    9.             ' Retrieve the Label, Image controls in the current DataListItem.
    10.  
    11.             Dim ContactLabel As Label = CType(e.Item.FindControl("lblContactName"), Label)
    12.             Dim DescriptionLabel As Label = CType(e.Item.FindControl("lblDescription"), Label)
    13.  
    14.             Dim AddressLabel As Label = CType(e.Item.FindControl("lblAddress"), Label)
    15.  
    16.             'create a reference to the DataSource of the DataList
    17.             Dim oData As System.Data.Common.DbDataRecord = CType(e.Item.DataItem, System.Data.Common.DbDataRecord)
    18.  
    19.             ContactLabel.Text = oData("ContactName")
    20.  
    21.             DescriptionLabel.Text = oData("ListingDescription")
    22.             AddressLabel.Text = oData("Address")
    23.  
    24.         End If
    25.     End Sub
    Last edited by brucevde; Aug 5th, 2004 at 02:19 AM.

  5. #5

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Excellent, things make sense now.

    BTW, we're making an ASP.NET application that uses the same treeview as you have. And it has the same display problems in FireFox. You might want to look into adding this style there:

    style=cursor:pointer; cursor:hand;

    (I assume you made that...)

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Yeah, that site is my first attempt at anything web-based, ever....

    What is Firefox? What display problems? Can you post a screenshot?

    Thanks.

  7. #7
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    FireFox is a Mozilla based browser, i certainly prefer to use it over IE but i have encountered numerous problems getting sites to look the same in both IE and mozilla due to the slightly different ways they obviously interpret html.

  8. #8
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Man... i'm glad others are using the code-behind to bind the data, instead of <% container.DataItem %>, and remember you don't have to use FindControl if you know the order of the controls...

    Originally posted by brucevde
    VB Code:
    1. Private Sub dlstDirectory_ItemDataBound(ByVal sender As Object, _
    2. ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)  _
    3. Handles dlstDirectory.ItemDataBound
    4.  
    5.          'check if the ItemDataBound event is firing for the
    6.          'Item and/or AlternatingItem rows.  
    7.          'Ignore the Header and Footer events
    8.         If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    9.               'create a reference to the DataSource of the DataList
    10.             Dim oData As System.Data.Common.DbDataRecord = CType(e.Item.DataItem, System.Data.Common.DbDataRecord)
    11.  
    12.         ' Retrieve the Label, Image controls in the current DataListItem.
    13.  
    14.             Dim myLabel As Label
    15.             myLabel= DirectCast(e.Item.FindControl("lblContactName"), Label)
    16.             myLabel.Text = oData("ContactName")
    17.  
    18.             myLabel = DirectCast(e.Item.FindControl("lblDescription"), Label)
    19.             myLabel.Text = oData("ListingDescription")
    20.  
    21.             [b]'controls you place in templates usually start at 1, and
    22.             'increment by 2 (all odd numbers)
    23.             myLabel  = DirectCast(e.Item.Controls(5),Label)<b>Here is a snippet of the procedure used by the business directory page i mentioned.
    24.  
    25. </b>
    26.             myLabel.Text = oData("Address")
    27.          
    28.         End If
    29.     End Sub
    [/B]

  9. #9

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by brucevde


    What is Firefox?
    Are you serious? It's a very rapidly rising browser, very popular nowadays. A lot of VBFers use it

    Here's the screenshot, attached.

    You'll see half the menu items missing, the cursor not becoming a hand, the text on top not highlighted, etc. I know it's probably not a major issue for you, bit I felt should point it out, since you're from/near Vancouver too

    Ignore the blue strip there though... those are the things I'm supposed to forget.
    Attached Images Attached Images  
    Last edited by mendhak; Aug 6th, 2004 at 12:34 AM.

  10. #10
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Thanks for the screen shot and the tips (you too nemaroller).

    I will have to try out this Firefox. I should probably get Netscape as well, to make sure everything works for that browser too. I also need to complete two other VB programs I am currently writing. Create my company's website. Investigate SharePoint Services for a client. Fix that Chamber site. Learn .NET.

    To hell with it. Saturday morning I'm off to the other coast for a weeks R & R. Where are you from?

    Go Canucks (if there is a season this year).

  11. #11

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by brucevde
    Where are you from?

    From way too many places, but that's an extremely long story. I've lived most of my life in Vancouver, so it's the closest thing I've got to a home. Kingsway & Boundary, Burnaby Heights, Kamloops... *sigh*

    Go Canucks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width