Micro Niche Builder
Closed Thread
Results 1 to 2 of 2

Thread: How to show data into datalist control?

  1. #1

    Question How to show data into datalist control?

    Can someone tell me how to show the data in datalist ?
    Data should be compulsorily in 2 columns. My back end is ms sql server


  2. Micro Niche Builder

  3. #2

    Default

    Quote Originally Posted by Amar View Post
    Can someone tell me how to show the data in datalist ?
    Data should be compulsorily in 2 columns. My back end is ms sql server
    Here is full code for display data in datalist control:

    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <html>
    <script language="VB" runat="server">
    Sub Page_Load(sender As Object, e As EventArgs)
    Dim myConnection As SqlConnection
    Dim myCommand As SqlDataAdapter
    ' Create a connection to the "pubs" SQL database located on the
    ' local computer.
    myConnection = New SqlConnection("server=localhost;" _
    & "database=pubs;Trusted_Connection=Yes")
    ' Connect to the SQL database using a SQL SELECT query to get all
    ' the data from the "Titles" table.
    myCommand = New SqlDataAdapter("SELECT * FROM Titles", myConnection)
    ' Create and fill a DataSet.
    Dim ds As DataSet = new DataSet()
    myCommand.Fill(ds)
    ' Bind MyDataList to the DataSet. MyDataList is the ID for
    ' the DataList control in the HTML section of the page.
    MyDataList.DataSource = ds
    MyDataList.DataBind()
    End Sub
    </script>

    <%-- Display the data. -%>
    <body>
    <%-- Open the DataList control and set it for two columns, to be
    filled in horizontal order. --%>
    <ASPataList id="MyDataList" RepeatColumns="2"
    RepeatDirection="Horizontal" runat="server">
    <ItemTemplate>
    <div style="padding:15,15,15,15;font-size:10pt;font-family:Verdana">
    <div style="font:12pt verdana;color:darkred">
    <i><b><%# DataBinder.Eval(Container.DataItem, "title")%>
    </i></b>
    </div>
    <br>
    <b>Title ID: </b>
    <%# DataBinder.Eval(Container.DataItem, "title_id") %><br>
    <b>Category: </b>
    <%# DataBinder.Eval(Container.DataItem, "type")%><br>
    <b>Publisher ID: </b>
    <%# DataBinder.Eval(Container.DataItem, "pub_id") %><br>
    <b>Price: </b>
    <%# DataBinder.Eval(Container.DataItem, "price", "{0:c}") %>
    <p>
    </div>
    </ItemTemplate>
    </ASPataList>
    </body>
    </html>

    [C#]
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <html>
    <script language="C#" runat="server">
    void Page_Load(Object sender, EventArgs e)
    {
    // Create a connection to the "pubs" SQL database located on the
    // local computer.
    SqlConnection myConnection = new SqlConnection("server=localhost;" +
    "database=pubs;Trusted_Connection=Yes");
    // Connect to the SQL database using a SQL SELECT query to get all
    // the data from the "Titles" table.
    SqlDataAdapter myCommand = new SqlDataAdapter("SELECT * " +
    " from Titles", myConnection);
    // Create and fill a DataSet.
    DataSet ds = new DataSet();
    myCommand.Fill(ds);
    // Bind MyDataList to the DataSet. MyDataList is the ID for
    // the DataList control in the HTML section of the page.
    MyDataList.DataSource = ds;
    MyDataList.DataBind();
    }
    </script>

    <%-- Display the data. -%>
    <body>
    <%-- Open the DataList control and set it for two columns, to be
    filled in horizontal order. --%>
    <ASPataList id="MyDataList" RepeatColumns="2"
    RepeatDirection= "Horizontal" runat="server">
    <%-- Create a DataList control template named "ItemTemplate". --%>
    <ItemTemplate>
    <div style="padding:15,15,15,15;font-size:10pt;
    font-family:Verdana">
    <div style="font:12pt verdana;color:darkred">
    <i><b><%# DataBinder.Eval(Container.DataItem, "title")%>
    </i></b>
    </div>
    <br>
    <b>Title ID: </b>
    <%# DataBinder.Eval(Container.DataItem, "title_id") %><br>
    <b>Category: </b>
    <%# DataBinder.Eval(Container.DataItem, "type")%><br>
    <b>Publisher ID: </b>
    <%# DataBinder.Eval(Container.DataItem, "pub_id") %><br>
    <b>Price: </b>
    <%# DataBinder.Eval(Container.DataItem,"price", "{0:c}") %>
    <p>
    </div>
    </ItemTemplate>
    </ASPataList>
    </body>
    </html>

Closed Thread

Similar Threads

  1. Television show template
    By ankur0412 in forum WordPress Themes & Templates
    Replies: 3
    Last Post: 09-30-2009, 06:56 AM
  2. How to bind data to grid?
    By nikon in forum ASP Help
    Replies: 7
    Last Post: 08-20-2009, 09:36 PM
  3. how to put the hyperlink in datalist
    By ruchi_patel in forum ASP Help
    Replies: 3
    Last Post: 06-23-2009, 08:43 AM
  4. Control Panels!
    By ankur0412 in forum Web Hosting Forums
    Replies: 6
    Last Post: 04-18-2009, 02:53 AM

Tags for this Thread

Bookmarks

Posting Permissions

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