.net
The text of this blog post could not be loaded. Read it on the old site: .net
Join the conversation! Your thoughts help the community grow.
Join to leave a comment
Members earn 10 SHARP for a comment, 10 SHARP for a reaction, and 250 SHARP for every blog they publish.
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegisterMembers onlyFeatured eBookClaude for AI-Native BuildersDownload nowWrite a blog post and earn +250 SHARP when it is approved.
Write a blog
pooja bhPosted Mar 25, 2010, 9:03 AM EDT
Imports System.Data Imports System.Data.SqlClient Partial Class gridreader Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Dim cmd As SqlCommand = New SqlCommand("SELECT *FROM Customers ORDER BY ContactName", New SqlConnection("Server=localhost;Database=northwind;Trusted_Connection=True;")) cmd.Connection.Open() dgrCustomers.DataSource = cmd.ExecuteReader() dgrCustomers.DataBind() cmd.Connection.Close() cmd.Connection.Dispose() End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" Me.EnableViewState = False Dim stringWriter As New System.IO.StringWriter() Dim htmlWriter As New System.Web.UI.HtmlTextWriter(stringWriter) dgrCustomers.RenderControl(htmlWriter) Response.Write(stringWriter.ToString()) Response.End() End Sub End Class on click of button will display information in excel sheet next is aspx file <%@ Page Language="VB" AutoEventWireup="false" CodeFile="sqldatareader.vb" Inherits="gridreader" %> <!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:Button ID="button1" runat="server" Text="click me"/> <asp:Label ID="lblOut" runat="server" Text="<h2>Northwind products</h2>" /> <asp:DataGrid ID="dgrCustomers" runat="server" BorderColor="black" BorderWidth="1" GridLines="Both" CellPadding="3" CellSpacing="0" Font-Names="verdana" /> <asp:label ID="lblStatus" runat="server"></asp:label> </div> </form> </body> </html>