Hi nauna,
Refer below sample.
HTML
<form id="form1" runat="server">
<asp:ListView ID="ListView1" runat="server" ClientIDMode="Static">
<ItemTemplate>
<asp:Label ID="lblid" Visible="false" runat="server" Text='<%#Eval("CustomerId") %>'></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="view">
<div>
<asp:Label ID="lblcompetecategories" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
</div>
</asp:LinkButton>
</ItemTemplate>
</asp:ListView>
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$.each($('[id*=lblcompetecategories]'), function (index, item) {
alert($(item).html());
});
});
</script>
Namespaces
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ListView();
}
}
private void ListView()
{
string constring = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("SELECT CustomerId, Name FROM Customers", con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
ListView1.DataSource = dt;
ListView1.DataBind();
}
}
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Me.ListView()
End If
End Sub
Private Sub ListView()
Dim constring As String = ConfigurationManager.ConnectionStrings("constring").ConnectionString
Using con As SqlConnection = New SqlConnection(constring)
Using cmd As SqlCommand = New SqlCommand("SELECT CustomerId, Name FROM Customers", con)
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Using dt As DataTable = New DataTable()
sda.Fill(dt)
ListView1.DataSource = dt
ListView1.DataBind()
End Using
End Using
End Using
End Using
End Sub
Screenshot