如何在ASP.NET中绑定HTML中的datalist [英] How to bind a datalist in HTML in ASP.NET

查看:64
本文介绍了如何在ASP.NET中绑定HTML中的datalist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从服务器端通过服务获取值返回xml中的值。在客户端使用响应来获取xml返回值。我想用html中的这个值绑定datalist。



我尝试了什么:



我尝试了很多方法,但是数据无法绑定。请帮助如何在asp.net中绑定datalist n html

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

推荐答案



试试这个例子

标记

Hi
Try this example
Markup
<!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>







代码背后(C#)






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]);
        }
    }
}


这篇关于如何在ASP.NET中绑定HTML中的datalist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆