Click here to Skip to main content
15,885,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am getting the values from server side through service return the value in xml.In Client Side am using the response to get the xml return value.I want to bind the datalist with this values in html.

What I have tried:

I tried Lots of method,But the datas Cannot be bind.Please help How to Bind the datalist n html in asp.net
Posted
Updated 29-Nov-16 19:56pm

1 solution

Hi
Try this example
Markup
HTML
<!DOCTYPE html>
<html>
<head>
    <title>Populate Data in HTML5 datalist using Asp.Net DataTable</title>
</head>
<body>
    <form id="form1" runat="server">
        <div style="padding:10px 5px;
            border:dashed 1px #CCC;
            width:300px;font:15px Arial;">

            Select Books <input list="books">
            <datalist id="books" runat="server"></datalist>
            
        </div>
    </form>
</body>
</html>



Code Behind (C#)

using System;

public partial class _Default : System.Web.UI.Page 
{
    System.Data.DataTable mytable = new System.Data.DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        CreateBooksTable();
        PopulateDataList();
    }

    private void CreateBooksTable()
    {
        System.Data.DataColumn tColumn = null;
        // TABLE COLUMNS.

        tColumn = new System.Data.DataColumn("Book ID", System.Type.GetType("System.String"));
        mytable.Columns.Add(tColumn);

        mytable.Rows.Add("Advanced Composite Material");
        mytable.Rows.Add("Asp.Net 4 Blue Book");
        mytable.Rows.Add("Teaching Science");
        mytable.Rows.Add("Circuit Bending");
        mytable.Rows.Add("ADOBE Premiere");
    }

    private void PopulateDataList()
    {
         for (int i = 0; i <= mytable.Rows.Count - 1; i++)
        {
            // ADD VALUES TO .
            books.InnerHtml = books.InnerHtml + System.Environment.NewLine + 
                String.Format("<option value='{0}'>", mytable.Rows[i][0]);
        }
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900