网格视图和列表视图 [英] grid view &list view

查看:117
本文介绍了网格视图和列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习asp.net.如何连接access2007以及如何在asp.net中使用网格视图
请发送一个用于网格View&access 2007的示例吗?

I am learning asp.net.how to connect access2007 and how to use grid view in asp.net
Please send the one example for grid View & access 2007?

推荐答案

查看这些示例
基本Gridview

http://shawpnendu.blogspot.com/2009/11/bind- gridview-with-ms-access-database.html [ ^ ]

Gridview中的操作
在ASP.NET 2.0中可编辑的GridView [ http://csharpdotnetfreak.blogspot.com/2011/04/gridview- examples-in-aspnet-20-35.html [ ^ ]
Look these samples
Basic Gridview

http://shawpnendu.blogspot.com/2009/11/bind-gridview-with-ms-access-database.html[^]

Operations in Gridview
Editable GridView in ASP.NET 2.0[^]

Gridview examples

http://csharpdotnetfreak.blogspot.com/2011/04/gridview-examples-in-aspnet-20-35.html[^]


尊敬的Vijaya,

该链接可以帮助您使用GridView:- http://csharpdotnetfreak. blogspot.com/2011/04/gridview-examples-in-aspnet-20-35.html [ www.youtube.com/watch?v=Hnu5qQyeAuA [
Dear Vijaya,

This link may help you out for GridView:- http://csharpdotnetfreak.blogspot.com/2011/04/gridview-examples-in-aspnet-20-35.html[^]


link for access connection:- www.youtube.com/watch?v=Hnu5qQyeAuA[^]


尝试以下代码... ...

Try this code......

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MSACCESSGV.aspx.cs" Inherits="MSACCESSGV" %>
<!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>Test MS ACCESS DATABASE CONNECTION</title>
</head>

<body>
<form id="form1" runat="server">
<div>

<asp:GridView ID="gvArticle" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Id" />
<asp:BoundField DataField="Category" HeaderText="Category" SortExpression="Title" />
<asp:BoundField DataField="Published" HeaderText="Published" SortExpression="Visit" />
<asp:BoundField DataField="Modified" HeaderText="Modified" SortExpression="Modified" />
</Columns>
</asp:GridView>

</div>
</form>

</body>
</html>




现在,您需要在服务器端编写代码以绑定GridView gvArticle.首先为您的MS Access数据库建立连接字符串.然后从MS Access数据库读取数据.完整的服务器端代码如下:




Now you need to write code in server side to bind GridView gvArticle. First make connection string for your MS Access Database. And then read data from MS Access database. Complete server side code is given below:

using System;
using System.Data;
using System.Web.UI;
using System.Data.OleDb;

public partial class MSACCESSGV : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
string sFilePath = Server.MapPath("MSACCESS.mdb");
DataTable dt;
OleDbConnection Conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sFilePath + ";");

using (Conn)
{
Conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM ARTICLE", Conn);
OleDbDataAdapter oDA = new OleDbDataAdapter(cmd);
dt = new DataTable();
oDA.Fill(dt);
}

gvArticle.DataSource = dt;
gvArticle.DataBind();

}
}
}


这篇关于网格视图和列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆