DataGrid in ASP.Net Using VB code

Posted by Senthilmcatyr under ASP.NET on 8/22/2011 | Points: 10 | Views : 1829 | Status : [Member] | Replies : 2
I create datagrid in ASP.Net. I run this application but automatically does not view datagrid. how to set automatically view gridview while when i was run?



Posted by: Jpchoudhari on: 8/22/2011 [Member] Starter | Points: 25

u have to assign a data source to your datagird and use datagrid's bind or page's bind method to bind the data to your grid.

why you want to show data automaticallay???

Kind Regards,

Senthilmcatyr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thiru on: 8/22/2011 [Member] Starter | Points: 25

Hope it will help you:

DataGrid.aspx page:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DataGrid.aspx.vb" Inherits="DataGrid" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<title>Using Data Grid</title>
<form id="Form1" runat="server">
<asp:DataGrid id="mydatagrid" runat="server" />
<asp:Label ID="lbl" runat="server" ForeColor="Brown" BackColor="AliceBlue"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" />

DataGrid.aspx.vb page:
Imports System.Data

Imports MySql.Data.MySqlClient
Partial Class DataGrid
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myconnection As MySqlConnection
Dim myDataAdapter As MySqlDataAdapter
Dim myDataSet As DataSet
Dim strSQL As String
myconnection = New MySqlConnection("server=localhost; user id=xxx; password=xxx; database=xxx;")
strSQL = "select * from tblmem;"
mydataadapter = New MySqlDataAdapter(strsql, myconnection)
myDataSet = New DataSet()
myDataAdapter.Fill(myDataSet, "tblmem")
mydatagrid.DataSource = myDataSet
End Sub
End Class

Note: To run automatically without button.
just copy the code from button_click event and paste it in page_load event.

Senthilmcatyr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response