ciao, vedi se è utile:
Io uso odbc per usare mysql.
vedi un pò te.
codice:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" %>
<%@ Import Namespace="System.Data.Odbc" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Configuration" %>
<script runat="server">
String connectionString = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
popola();
}
private void popola()
{
OdbcConnection conn = new OdbcConnection(connectionString);
string SQL = "SELECT * FROM news WHERE _status='1';";
OdbcCommand objCommand = new OdbcCommand(SQL, conn);
DataSet ds = new DataSet();
OdbcDataAdapter da = new OdbcDataAdapter(objCommand);
da.Fill(ds);
MyGrid.DataSource = ds;
MyGrid.DataBind();
}
protected void MyGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
MyGrid.PageIndex = e.NewPageIndex;
popola();
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="lblMsg" runat="server"></asp:Label>
<div class="post">
<asp:GridView ID="MyGrid" runat="server" GridLines="None" EmptyDataText="Non ci sono dati"
AllowPaging="true" PageSize="10" AutoGenerateColumns="false" Width="100%" BorderStyle="None"
ShowHeader="false" ShowFooter="true"
onpageindexchanging="MyGrid_PageIndexChanging" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<h1 class="title"><%# Eval("_subject") %></h1>
<%# Eval("_contentHome")%>
<p align="right"><%# Eval("_name") %></p>
<div class="meta">
<p class="links">" class="comments">Comments (*) • " class="more">Leggi tutto»</p>
</div>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</asp:Content>
ciao.