Angular 12 CRUD Example
In this article, we will learn angular 12 CRUD example with web API as well as way to implement cascading dropdown, searching, sorting, and pagination...
May 30, 2021 read moreIn this article, we will learn angular 12 CRUD example with web API as well as way to implement cascading dropdown, searching, sorting, and pagination...
May 30, 2021 read moreIn this article i am going to explain how you can use angular js table with bootstrap 4 in asp.net web form, and also show you how you can display records...
December 08, 2018 read moreCodingvila also allowing a guest post for digital marketing, where you can explore your business, product, or services in terms of articles. write quality.......
August, 21, 2021 read moreIn this article, we will learn how to create a bar chart in angular 12 using ng2-charts. Here, I'll explain how to create an angular 12 project in visual........
May 29, 2021 read moreThis article gives an explanation about convert Datatable to CSV in c# and explains the efficient way to write CSV files from Datatable as well as show...
March 01, 2020 read moreThis article provides an explanation about how to merge multiple pdf files into single pdf in using Itextsharp in c# here I also explained the use of Itextsharp.
January 22, 2019 read more![]() |
Read CSV File |
![]() |
Create Website in Visual Studio |
![]() |
Empty Web Site |
![]() |
Add Web Form |
![]() |
Web Form |
<style type="text/css"> body { font-family: Arial; font-size: 10pt; } table { border: 1px solid #ccc; border-collapse: collapse; background-color: #fff; } table th { background-color: #ff0097; color: #fff; font-weight: bold; } table th, table td { padding: 5px; border: 1px solid #ccc; } table, table table td { border: 0px solid #ccc; } .button { background-color: #223c88; /* Blue */ border: none; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; } </style>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="CS" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } table { border: 1px solid #ccc; border-collapse: collapse; background-color: #fff; } table th { background-color: #ff0097; color: #fff; font-weight: bold; } table th, table td { padding: 5px; border: 1px solid #ccc; } table, table table td { border: 0px solid #ccc; } .button { background-color: #223c88; /* Blue */ border: none; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; } </style> </head> <body> <form id="form1" runat="server"> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID="btnRead" CssClass="button" runat="server" Text="Import" OnClick="ReadCSV" /> <hr /> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </form> </body> </html>
using System.IO; using System.Data;
Imports System.IO Imports System.Data
protected void ReadCSV(object sender, EventArgs e) { //Upload and save the file string csvPath = Server.MapPath("~/Files/") + Path.GetFileName(FileUpload1.PostedFile.FileName); FileUpload1.SaveAs(csvPath); //Create a DataTable. DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[6] { new DataColumn("Id", typeof(int)), new DataColumn("CustomerName", typeof(string)), new DataColumn("Item", typeof(string)), new DataColumn("Qty", typeof(Int32)), new DataColumn("Price", typeof(Decimal)), new DataColumn("Amount",typeof(Decimal)) }); //Read the contents of CSV file. string csvData = File.ReadAllText(csvPath); //Execute a loop over the rows. foreach (string row in csvData.Split('\n')) { if (!string.IsNullOrEmpty(row)) { dt.Rows.Add(); int i = 0; //Execute a loop over the columns. foreach (string cell in row.Split(',')) { dt.Rows[dt.Rows.Count - 1][i] = cell; i++; } } } //Bind the DataTable. GridView1.DataSource = dt; GridView1.DataBind(); }
Protected Sub ReadCSV(sender As Object, e As EventArgs) 'Upload and save the file Dim csvPath As String = Server.MapPath("~/Files/") + Path.GetFileName(FileUpload1.PostedFile.FileName) FileUpload1.SaveAs(csvPath) 'Create a DataTable. Dim dt As New DataTable() dt.Columns.AddRange(New DataColumn(5) {New DataColumn("Id", GetType(Integer)), New DataColumn("CustomerName", GetType(String)), New DataColumn("Item", GetType(String)), New DataColumn("Qty", GetType(Int32)), New DataColumn("Price", GetType(Decimal)), New DataColumn("Amount", GetType(Decimal))}) 'Read the contents of CSV file. Dim csvData As String = File.ReadAllText(csvPath) 'Execute a loop over the rows. For Each row As String In csvData.Split(ControlChars.Lf) If Not String.IsNullOrEmpty(row) Then dt.Rows.Add() Dim i As Integer = 0 'Execute a loop over the columns. For Each cell As String In row.Split(","c) dt.Rows(dt.Rows.Count - 1)(i) = cell i += 1 Next End If Next 'Bind the DataTable. GridView1.DataSource = dt GridView1.DataBind() End Sub
![]() |
CSV |
Codingvila provides articles and blogs on web and software development for beginners as well as free Academic projects for final year students in Asp.Net, MVC, C#, Vb.Net, SQL Server, Angular Js, Android, PHP, Java, Python, Desktop Software Application and etc.
Hi I'm confused about the use of the Gridview1 property, I can't access this from my C# code and I'm wondering where it's declared? Right now I'm getting an error underneath it
Gridview1 is declared in CS.aspx.cs file. That is a aspx control written in the cs.aspx.cs file .
Make sure you have this code in your cs.aspx.cs file.
Hey how to display only particular columns from CSV file into grid view
Thank you for your valuable time, to read this article, If you like this article, please share this article and post your valuable comments.
Once, you post your comment, we will review your posted comment and publish it. It may take a time around 24 business working hours.
Sometimes I not able to give detailed level explanation for your questions or comments, if you want detailed explanation, your can mansion your contact email id along with your question or you can do select given checkbox "Notify me" the time of write comment. So we can drop mail to you.
If you have any questions regarding this article/blog you can contact us on info.codingvila@gmail.com
Tutup Konverter!sentiment_satisfied Emoticon