Followers

Follow by Email

Cloud Labels

[Fixing] Report Viewer control toolbar in Google Chrome [Solved] How to kill any process using VB.NET ABAP Admin Panel Template adonet Affiliate site Airline Reservation System Project in PHP Ajax Android androidstudio AngularJS aspnet Big Data Blogger Bookmarking Bootstrap 4 C# C#.Net How To: Send email in asp.net using c# cloud computing Computer Programming CRYSTALREPORTS CSS Databases and ADO.NET DevOps Django dotnet E-commerce Website Php MySQL source code free download Employee Leave Management System in PHP/MySql with Full Source Code Firebase Free Sourcecode in PHP Free Asp.net SourceCode Free SourceCode in C# FreeSourcecode FreeSourcecodevb.net FreeSourcecodinPHP fullform google Google Fuchsia Hospital Management System with C# with Full Source Code How To Assign a Value to a Variable in Python How to Bind Data to Repeater Control in Asp.net How to generate QR Code in C# windows application HOW TO GENERATE RANDOM NUMBER IN C# how to ping ip address in asp net How To Read A Text File In C# How to Use Anchoring Controls In visual c#.net How To Using LINQ to SQL Classes With Example HTML HTML Head Title Access Denied Image Submission Sites introduction to csharp programming JavaProject javascript jQuery Library Management System Using PHP and MySQL with Full Source Code LINQ LINQ In C#.Net MangoDB Microsoft Mobile Blazor mvc MySQL Nodejs NuGet Online Blood Bank Management System Project Online Class and Exam Scheduling System in PHP PhotoshopCs5 PHP pm mandhan yojana PMYOJANA Project python QR (Quick Response) Code Generator using C#.NET Querying a Database with LINQ to SQL sap SAP Basis And Security SAP ECC 6.0 Installation Step by Step SAPMM SarkariNukari sbi School Fees Payment System in PHP With Source code SearchEngine Site seo SEO Tutorials software sql SQLite StringBuilder Class In C# TechNews Timer ajax control In Asp.net Top Most Popular Social Bookmarking TRICK TIPS VB.NET VB.NET Classes VB.NET Conditional Statements VB.NET Loops vbnet visual studio download What are variables? what is JavaScript? What is Link Building? What is Node.Js? whatsappgb Windows Forms WordPress

Labels

ASP. Net ListView DataBinding Tutorial

ASP. Net ListView DataBinding Tutorial,Templates in ListView,Flexibility in rendering,DataBinding is quiet similar to GridView
Share it:

ASP. Net ListView DataBinding Tutorial

For presenting data in list form, we have several options in Asp.Net like ListView, DataList, Repeater, GridView, DropDownList, etc.
Since we have a variety of controls to choose from, the control can be selected based on specific requirements. For e.g. single column with a single selection, the DropDownList is a perfect choice. 
If paging, sorting, the edit is required then GridView will be the right choice. If just need to repeat some HTML code, then Repeater will work out to be better. This article is focused on ListView.





DataBinding is quiet similar to GridView


DataBinding in ListView is almost similar to GridView. There is not much difference. There is a requirement for ItemPlaceHolder. By default the name of that place holder is itemPlaceholder. Asp.Net allows us to custom name (id) also
.

Flexibility in rendering


This ListView is one of the best controls while flexibility is taken into consideration. With the concept of Item Place Holder, we can specify/ configure where the items have to be placed (rotated). In this example, I have made a two-column layout with liquid flow. The number of horizontal cells can be adjusted based on the resolution while resizing the browser.


Templates in ListView


There are a few templates that will ease the development effort using ListView. If you have worked in GridView earlier, then basic templates in ListView are similar to GridView Templates. There are a few special templates. I am highlighting the templates in the following list. These templates can be used to customize rendering.

  • LayoutTemplate
  • GroupTemplate
  • ItemTemplate
  • AlternatingItemTemplate
  • EditItemTemplate
  • InsertItemTemplate
  • ItemSeparatorTemplate
  • GroupSeparatorTemplate
  • EmptyItemTemplate
  • EmptyDataTemplate
  • SelectedItemTemplate


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="WebApplication2.index" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
        <asp:ListView runat="server" ID="ListView1">
            <LayoutTemplate>
                <div id="Div1" runat="server" style="width: 100%; border: solid 2px red">
                    <div id="Div2" runat="server" style="float: right; width: 73%; border: solid 2px green">
                        <asp:Panel runat="server" ID="itemPlaceholder">
                        </asp:Panel>
                    </div>
                    <div runat="server" id="Panel1" style="float: left; width: 25%; border: solid 2px blue">
                        My ListView Test
                    </div>
                </div>
            </LayoutTemplate>
            <ItemTemplate>
                <div style="float: left; margin: 2px; width: 24%; border: solid 1px silver; height: 60px;">
                    <asp:Label runat="server" ID="lblName" Font-Bold="true" Text='<%# DataBinder.Eval(Container.DataItem, "ProductName")%>'>
                    </asp:Label>
                    <br /><asp:CheckBox runat="server" ID="chkDiscontinued" Text="Discontinued"
                    Checked='<%# DataBinder.Eval(Container.DataItem, "Discontinued")%>' />
                </div>
            </ItemTemplate>
        </asp:ListView>
        <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="10">
            <Fields>
                <asp:NumericPagerField />
            </Fields>
        </asp:DataPager>
   
    </div>
    </form>
</body>
</html>


Imports System.Data.SqlClient
Imports System.Data
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, _
                            ByVal e As System.EventArgs) Handles Me.Load
        If (Not IsPostBack) Then
            BindListView()
        End If
    End Sub
    Private Sub BindListView()
        ListView1.DataSource = GetData(String.Empty)
        ListView1.DataBind()
    End Sub
    Private ReadOnly Property ConnectionString() As String
        Get
            Return "Server=.\SQLEXPRESS;Database=NorthWind;Trusted_Connection=True"
        End Get
    End Property
    Private ReadOnly Property Connection() As SqlConnection
        Get
            Dim ConnectionToFetch As New SqlConnection(ConnectionString)
            ConnectionToFetch.Open()
            Return ConnectionToFetch
        End Get
    End Property
    Public Function GetData(ByVal Expression As String) As DataSet
        Dim SelectQry = "select * from Products"
        Dim SampleSource As New DataSet
        Dim SampleDataAdapter As New SqlDataAdapter(SelectQry, ConnectionString)
        SampleDataAdapter.Fill(SampleSource)
        Return SampleSource
    End Function
    Private Sub ListView1_PagePropertiesChanging(ByVal sender As Object, _
                ByVal e As PagePropertiesChangingEventArgs) Handles ListView1.PagePropertiesChanging
        DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, False)
        BindListView()
    End Sub
Share it:

aspnet

VB.NET

Post A Comment: