Utilizzo di un GridView con un DataTable

FAQ di programmazione in .NET

Utilizzo di un GridView con un DataTable

Messaggioda alesslud » dom set 09, 2007 8:10 pm

Utilizzo di un GridView con un DataTable


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using MySql.Data.MySqlClient;

public partial class test_Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MySqlConnection conn = new MySqlConnection();
DataTable myDataTable = new DataTable();
ConnectionMysql myConn = new ConnectionMysql();
conn = myConn.getConnection();
MySqlCommand command = new MySqlCommand("select * from test", conn);
MySqlDataReader reader = command.ExecuteReader();
Console.WriteLine("Ciao");
myDataTable.Load(reader);
GridView1.DataSource = myDataTable;
GridView1.DataBind();
}
}
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

La pagina aspx

Messaggioda alesslud » dom set 09, 2007 8:11 pm

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="test_Test" %>

<!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:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</form>
</body>
</html>
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am


Torna a .NET

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite

cron