locked
data representation using dynamic array of labels? RRS feed

  • Question

  • User-666082118 posted

     I have a dataset which has 4 field columns and variable number of rows depending upon the records existing in database....When i query i want the dataset to be loaded as text in labels....i have the count(number of rows) present in the dataset...How can i proceed????

    Friday, November 7, 2008 3:37 AM

Answers

  • User-990694832 posted

    yep,

    dim sb as new system.t .....stringbuilder

    DK

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 9, 2008 2:19 PM

All replies

  • User-990694832 posted

    Why not use a gridview control ?  why is an array of labels needed ?

    but a person could do this in a generic list(of label)

    Hope this helps

    DK 

     

    Friday, November 7, 2008 9:13 AM
  • User-666082118 posted

    Actually i am making a portal and want to display the announcements(or events)..these are usually shown in form of labels in the web sites...gridview is not preffered..so can u guide me????

    Friday, November 7, 2008 10:11 AM
  • User-990694832 posted

    ok how about something like this

    for each row in dataset
          dim lbl as new label
         dim sb as sytem.text.stringbuilder
         sb.append(row.field1)
          ...
          sb.append(row.fieldn-1)

          lbl.text =sb.tostring()

    your container.add(lbl)    ' a div a form whatever container your using
    next

     

    Hope this helps

    DK

    Friday, November 7, 2008 10:38 AM
  • User-666082118 posted

    I tried this but it shows null ref exception

      Dim ds3 As New DataSet

                Dim da As New OleDbDataAdapter(con.cmd)

                da.Fill(ds3)
                count = ds3.Tables(0).Rows.Count

                Dim dr As DataRow

                For Each dr In ds3.Tables(0).Rows
                    Dim lbl As New Label
                    Dim sb As System.Text.StringBuilder
                'exception on next line

                    sb.Append(dr("date").ToString)
                    sb.Append(dr("announcement").ToString)
                    sb.Append(dr("[desc]").ToString)
                    sb.Append(dr("ctitle1").ToString)

                    lbl.Text = sb.ToString()

                    Controls.Add(lbl)    ' a div a form whatever container your using
                Next

    Saturday, November 8, 2008 1:49 PM
  • User-990694832 posted

    What is giving the null reference ?

    may be datarow ?

    Try this

    For Each dr as datarow In ds3.Tables(0).Rows

    ....

    next

    or a collumn in the row ?

    Hope this helps

    DK 

     

     

     

    Saturday, November 8, 2008 5:44 PM
  • User-666082118 posted

     dr is not giving null refernce exception...the exception is at  sb.Append(dr("date").ToString)

    it is:

    <title>Untitled Page</title>System.NullReferenceException: Object reference not set to an instance of an object. 

    Sunday, November 9, 2008 1:09 AM
  • User-666082118 posted

     is there something that sb has to be initialized to????It also says sb is used before it is assgined any value.....i guess instead append property some other has to be used?

    Sunday, November 9, 2008 1:12 AM
  • User-990694832 posted

    yep,

    dim sb as new system.t .....stringbuilder

    DK

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 9, 2008 2:19 PM
  • User-666082118 posted

     ya its working thanks a lot

    Tuesday, November 11, 2008 4:06 AM
  • User-666082118 posted

     ya its working thanks a lot

    Tuesday, November 11, 2008 4:09 AM