---
title: "How to bind data table with listview?"  
description: "How to bind data table with listview?"  
author: "Pravesh Singh"  
published: 2012-08-17  
updated: 2012-08-18  
canonical: https://www.mindstick.com/forum/437/how-to-bind-data-table-with-listview  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# How to bind data table with listview?

Hello Everyone,\
I'm facing a [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) since last night, actually I want to [bind data](https://www.mindstick.com/forum/415/how-to-bind-data-in-windows-phone-7-using-wcf-service) [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) with [asp](https://www.mindstick.com/articles/751/introduction-to-asp-dot-net-mvc) [listview](https://www.mindstick.com/articles/12744/listview-in-android) [control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control) but I don't have an idea how to do it. Please [resolve](https://www.mindstick.com/forum/159427/windows-app-dll-not-found-resolve-library-issue) my problem as soon as possible. Please paste [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) if possible. \
\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!!

## Replies

### Reply by AVADHESH PATEL

Hello Pravesh\
\
like gridview binding we can't bind listview so for binding listview take help of below code.\

```
private void btnDisplay_Click(object sender, EventArgs e)        {            // Create Data Table for MS-Office 2007 or 2003            System.Data.DataTable dtExcel = new System.Data.DataTable();            //DataTable Name            dtExcel.TableName = "MyExcelData";            //Path of excel file in local drive            string SourceConstr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='F:\avi\information.xlsx';Extended Properties= 'Excel 8.0;HDR=Yes;IMEX=1'";            //connectin            OleDbConnection con = new OleDbConnection(SourceConstr);            //Query string            string query = "Select * from [Sheet1$]";            //DataAdapter object            OleDbDataAdapter data = new OleDbDataAdapter(query, con);            //fill record into DataTable            data.Fill(dtExcel);            // Attach Subitems to the ListView            listView1.Columns.Add("Name", 100, HorizontalAlignment.Left);            listView1.Columns.Add("Address", 100, HorizontalAlignment.Left);            listView1.Columns.Add("Contact", 100, HorizontalAlignment.Left);            listView1.Columns.Add("Email Id", 100, HorizontalAlignment.Left);            // Clear the ListView control            listView1.Items.Clear();            // Display items in the ListView control            for (int i = 0; i < dtExcel.Rows.Count; i++)            {                DataRow drow = dtExcel.Rows[i];                // Only row that have not been deleted                if (drow.RowState != DataRowState.Deleted)                {                    // Define the list items                    ListViewItem lvi = new ListViewItem(drow["Name"].ToString());                    lvi.SubItems.Add(drow["Address"].ToString());                    lvi.SubItems.Add(drow["Contact"].ToString());                    lvi.SubItems.Add(drow["Email Id"].ToString());                    // Add the list items to the ListView                    listView1.Items.Add(lvi);                }            }           }
```

\
I hope it might be resolve your problem.


---

Original Source: https://www.mindstick.com/forum/437/how-to-bind-data-table-with-listview

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
