Populate (Bind) ListView using jQuery AJAX in ASP.Net SQL Server XML DataTable DataSet Web Method

Complete CODE is given below:
Here he has explained with an example, how to populate (bind) ListView using jQuery AJAX in ASP.Net with C# and VB.Net.

This video will illustrate how to populate ASP.Net ListView control from SQL Server Database on Client Side by calling WebMethod using jQuery AJAX in ASP.Net with C# and VB.Net.
https://www.aspsnippets.com/categories//articles/populate-bind-listview-using-jquery-ajax-in-aspnet.aspx



Customer Id ContactName Country




<%# Eval("CustomerId") %> <%# Eval("ContactName") %> <%# Eval("Country") %>



—-
using System.Data;
using System.Web.Services;
using System.Configuration;
using System.Data.SqlClient;
—-
Imports System.Data
Imports System.Web.Services
Imports System.Configuration
Imports System.Data.SqlClient
—-
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dummy = new DataTable();
dummy.Columns.Add(“CustomerID”);
dummy.Columns.Add(“ContactName”);
dummy.Columns.Add(“Country”);
dummy.Rows.Add();
lvCustomers.DataSource = dummy;
lvCustomers.DataBind();
}
}
—-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dummy As DataTable = New DataTable()
dummy.Columns.Add(“CustomerID”)
dummy.Columns.Add(“ContactName”)
dummy.Columns.Add(“Country”)
dummy.Rows.Add()
lvCustomers.DataSource = dummy
lvCustomers.DataBind()
End If
End Sub
—-
[WebMethod]
public static string GetCustomers()
{
string constr = ConfigurationManager.ConnectionStrings[“constr”].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = “SELECT TOP 10 CustomerID, ContactName, Country FROM Customers”;
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
sda.Fill(ds);
return ds.GetXml();
}
}
}
}
—-

Public Shared Function GetCustomers() As String
Dim constr As String = ConfigurationManager.ConnectionStrings(“constr”).ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand()
cmd.CommandText = “SELECT TOP 10 CustomerID, ContactName, Country FROM Customers”
cmd.Connection = con
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As DataSet = New DataSet()
sda.Fill(ds)
Return ds.GetXml()
End Using
End Using
End Using
End Function
—-

Post Author: hatefull