using System.Data;
using System.Data.SqlClient; using System.Collections;
namespace AspxGridView {
public class SysLogDAL {
static string _connectionstring = \数据库连接字符\ public static ICollection GetAllLog() {
ArrayList al = new ArrayList(); DataSet currentDs = new DataSet();
using (SqlConnection currentConn = new SqlConnection(_connectionstring)) {
//获取数据 currentConn.Open();
SqlDataAdapter currentSda = new SqlDataAdapter(\ currentSda.Fill(currentDs, \
DataTable dt = currentDs.Tables[\ foreach (DataRow dr in dt.Rows) {
SysLogEntry e = new SysLogEntry();
e.LogID = Int32.Parse(dr[\
e.OCCDatetime = DateTime.Parse(dr[\ e.Event = dr[\ e.Type = dr[\ e.Creator = dr[\
e.CreateDate = DateTime.Parse(dr[\ e.Remark = dr[\ al.Add(e); }
currentConn.Close(); } return al; } } }
其中SysLogEntry.cs代码如下:
using System;
using System.Collections.Generic; using System.Linq; using System.Web;
namespace AspxGridView {
public class SysLogEntry {
public int LogID { get; set; }
public DateTime OCCDatetime { get; set; }
public string Event { get; set; }
public string Type { get; set; }
public string Creator { get; set; }
public DateTime CreateDate { get; set; }
public string Remark { get; set; } } }
4.使用DataSourceID属性绑定LinqDataSource
ContextTypeName=\ 其中AspxGridView.SysLogDAL有一个SysLogEntrys的属性,代码如下(其它代码同例3) public ICollection SysLogEntrys { get { return this.GetAllLog(); ; } } 5.使用DataSourceID属性绑定XmlDataSource 其中Sys_Log.xml文件内容如下 3.为AspxGridView绑定嵌套数据 在AspxGridView中允许绑定嵌套数据。也就是一条数据允许再绑定该数据的下级数据。 举个很简单的例子,我们用AspxGridView来显示中国所有省份,然后我们可以为每行数据(每个省)再绑定一个下级数据,也就是每个省对应的所有市的信息,以此类推,我们还可以为每个市再绑定所有县的信息,层层级推。具体展示在页面上就是AspxGridView上的每条数据前面都有一个+号,展开+号,就可以看到下级数据了。 那么应该怎么来绑定嵌套数据呢? 首先要通过设置父AspxGridView的ShowDetailRow=true来开启嵌套。 子AspxGridView定义在父AspxGridView的 例:Asp.Net代码 OnBeforePerformDataSelect=\ SelectCommand=\查询主表数据的SQL语句\ SelectCommand=\查询从表数据的SQL语句\