How to display N records from a database in some Div's? Thanks.

Discussion in 'ASP .Net' started by Shapper, Apr 21, 2005.

  1. Shapper

    Shapper Guest

    Hello,

    In a database table named t_content I have the following records:

    id page name content
    1 index introduction
    Introduction Text
    2 index welcome Welcome Text

    3 index notes
    4 contacts address Mailing Address

    In index.aspx I want to display the content text from records 1, 2 and 3
    in three existing div's. Something as:
    <div id="introduction">Introduction Text</div>
    <div id="welcome">Welcome Text</div>
    <div id="notes">&nbsp;</div> << "&nbsp;" is used when content is
    empty.

    As far as I understand I should retrieve all the fields which
    page="index".

    Then i should create N variables such as:
    var_ { [name] from record 1} = { [content] from record 1}
    var_ { [name] from record 2} = { [content] from record 2}
    ....

    For the table example it would become something as:
    <div id="introduction">var_introduction</div>
    <div id="welcome">var_welcome</div>
    <div id="notes">var_notes</div>

    Where:
    var_introduction = "Introduction Text"
    var_welcome = "Welcome Text"
    var_notes = "&nbsp;"

    Is my plan the right way to do something like this?
    Can someone help me out in doing this?

    I had created a dataset (See the end of post) from my table where I
    filter a certain page where @page = ... and @name = ....
    It's working fine. Now I need to change this to have something as I
    described.

    Thank You,
    Miguel

    Here is my dataset:

    ASPX

    ....
    <% @Import Namespace="System.Data" %>
    <% @Import Namespace="System.Data.SqlClient" %>
    <script runat="server">
    Function dsContent(ByVal page As String, ByVal name As String) As
    System.Data.DataSet
    Dim connectionString As String =
    System.Configuration.ConfigurationSettings.AppSettings("connectionString")
    Dim dbConnection As System.Data.IDbConnection = New
    System.Data.OleDb.OleDbConnection(connectionString)
    Dim queryString As String = "SELECT [t_content].* FROM
    [t_content] WHERE (([t_content].[page] = @page) AND ([t_content].[name]
    = @name))"
    Dim dbCommand As System.Data.IDbCommand = New
    System.Data.OleDb.OleDbCommand
    dbCommand.CommandText = queryString
    dbCommand.Connection = dbConnection
    Dim dbParam_page As System.Data.IDataParameter = New
    System.Data.OleDb.OleDbParameter
    dbParam_page.ParameterName = "@page"
    dbParam_page.Value = page
    dbParam_page.DbType = System.Data.DbType.String
    dbCommand.Parameters.Add(dbParam_page)
    Dim dbParam_name As System.Data.IDataParameter = New
    System.Data.OleDb.OleDbParameter
    dbParam_name.ParameterName = "@name"
    dbParam_name.Value = name
    dbParam_name.DbType = System.Data.DbType.String
    dbCommand.Parameters.Add(dbParam_name)
    Dim dataAdapter As System.Data.IDbDataAdapter = New
    System.Data.OleDb.OleDbDataAdapter
    dataAdapter.SelectCommand = dbCommand
    Dim dataSet As System.Data.DataSet = New System.Data.DataSet
    dataAdapter.Fill(dataSet)
    Return dataSet
    End Function
    </script>
    <html>
    ....

    Web.Config
    ....
    <appSettings>
    <add key="connectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;
    Ole DB Services=-4; Data Source=C:\db.mdb" />
    </appSettings>
     
    Shapper, Apr 21, 2005
    #1
    1. Advertising

  2. Shapper

    Lucas Tam Guest

    "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in news:
    #:

    > As far as I understand I should retrieve all the fields which
    > page="index".
    >
    > Then i should create N variables such as:
    > var_ { [name] from record 1} = { [content] from record 1}
    > var_ { [name] from record 2} = { [content] from record 2}


    Why not just loop your dataset and output?

    No need for so many variables.

    --
    Lucas Tam ()
    Please delete "REMOVE" from the e-mail address when replying.
    http://members.ebay.com/aboutme/coolspot18/
     
    Lucas Tam, Apr 21, 2005
    #2
    1. Advertising

  3. Shapper

    Shapper Guest

    What do you mean?

    Cheers,
    Miguel

    "Lucas Tam" <> wrote in message
    news::

    > "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in news:
    > #:
    >
    >
    > > As far as I understand I should retrieve all the fields which
    > > page="index".
    > >
    > > Then i should create N variables such as:
    > > var_ { [name] from record 1} = { [content] from record 1}
    > > var_ { [name] from record 2} = { [content] from record 2}

    >
    >
    > Why not just loop your dataset and output?
    >
    > No need for so many variables.
    >
    > --
    > Lucas Tam ()
    > Please delete "REMOVE" from the e-mail address when replying.
    > http://members.ebay.com/aboutme/coolspot18/
     
    Shapper, Apr 21, 2005
    #3
  4. Shapper

    Shapper Guest

    Hi,

    I think I can't use the dataset itself because I will not know which
    record I need to use in each div. So I believe by using variables which
    identify each record is maybe the best way (OR NOT?):

    var_ { [name] from record 1} = { [content] from record 1}

    So I think maybe I should create these variables from the dataset? What
    do you think?

    Something like:

    For i = 1 to N < N is the number of rows of the
    dataset.
    if content(i) is empty then
    var_[name(i)]="&nbsp;"
    else
    var_[name(i)]=[content)i)]
    endif
    end

    Then in the div I should use something like:
    <%# var_name %> ????

    My problem is how to create these 2 pieces of code as I never done
    something like this in ASP.NET.

    Thanks,
    Miguel

    "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
    news:mdmoura*NOSPAM*@gmail.*DELETE2SEND*com:

    > What do you mean?
    >
    > Cheers,
    > Miguel
    >
    > "Lucas Tam" <> wrote in message
    > news::
    >
    >
    > > "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in news:
    > > #:
    > >
    > >

    >
    > > > As far as I understand I should retrieve all the fields which
    > > > page="index".
    > > >
    > > > Then i should create N variables such as:
    > > > var_ { [name] from record 1} = { [content] from record 1}
    > > > var_ { [name] from record 2} = { [content] from record 2}

    > >
    > >

    >
    > > Why not just loop your dataset and output?
    > >
    > > No need for so many variables.
    > >
    > > --
    > > Lucas Tam ()
    > > Please delete "REMOVE" from the e-mail address when replying.
    > > http://members.ebay.com/aboutme/coolspot18/
     
    Shapper, Apr 21, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Spits

    How to display 3 records of a database?

    Steven Spits, Jun 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    351
    Miguel Dias Moura
    Jun 5, 2004
  2. K Viltersten

    <div ... /> and <div ...></div>

    K Viltersten, Mar 30, 2009, in forum: ASP .Net
    Replies:
    4
    Views:
    763
  3. Dwayne Madsen

    Q: Div A inside Div B is larger than Div B

    Dwayne Madsen, Jun 1, 2005, in forum: Javascript
    Replies:
    1
    Views:
    201
    David Dorward
    Jun 1, 2005
  4. mscir
    Replies:
    3
    Views:
    324
    Martin Honnen
    Jun 26, 2005
  5. Patrick
    Replies:
    1
    Views:
    332
    Patrick
    Jun 8, 2006
Loading...

Share This Page