In this blog we will know how to upload a excel file and display the contents of the file into a Gridview.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Display_excel_files_in_Gridview._Default"
%>
<!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>Untitled Page</title>
</head>
<body>
<form
id="form1"
runat="server">
<div>
<asp:Table
ID="TableButtons"
runat="server">
<asp:TableRow ID="TableRow1" runat="server">
<asp:TableCell ID="TableCell1" runat="server">
<asp:Button ID="ButtonUpload" runat="server"
Text="Upload Excel
Files" OnClick="ButtonUpload_Click" />
</asp:TableCell>
<asp:TableCell ID="TableCell2" runat="server">
<asp:Button ID="ButtonView" runat="server"
Text="View Excel Data" OnClick="ButtonView_Click" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:Panel
ID="PanelUpload"
runat="server"
Visible="False">
<asp:FileUpload ID="FileUploadExcel" runat="server" />
<br />
Please select an Excel file to import:<br />
<asp:Button ID="ButtonUploadFile" runat="server"
Text="Upload File" OnClick="ButtonUploadFile_Click" /><br />
<asp:Label ID="LabelUpload"
runat="server"
Text=""></asp:Label>
</asp:Panel>
<asp:Panel
ID="PanelView"
runat="server"
Visible="False">
<asp:Label ID="LabelGrid" runat="server" Text=""></asp:Label>
<asp:GridView ID="GridViewExcel" runat="server" BackColor="#DEBA84" BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />

Join the conversation! Your thoughts help the community grow.