|
雾里看花
水中月 |
thisAdapter.Fill(thisDataSet,"tb");
DataTable thisTable = thisDs.Tables["tb"];
DataView thisView = new DataView(thisTable); //创建DataView对象
thisView.RowFilter = ....;
DataGrid.DataSource = thisView;
...
a,使用sort属性对数据进行排序
thisView.Sort = "ProductName ASC";
or
thisView.Sort = "Age ASC , Name DESC";
b,使用RowFilter属性对数据过滤
thisView.RowFilter =
"ID = 10";
"Num <= 10";
"Date > 1/1/1999 and Date <= 2/2/2005";
"Product in ('apple','cat','table')"
"Text like = '*son'";
注:使用的各条件可用 and 继续添加,在使用 *** in ('','','') 时,注意括号内的项目不易过多,估计能支持十几个.
1,按一对x,y坐标筛选数据 x1 x2 y1 y2
thisView .RowFilter =
"HZBY >= '" + x1 + "' and HZBY <= '" + x2 + "' and ZZBX >= '" + y1 + "' and ZZBX <= '" + y2 + "'";
2,由数组生成筛选条件
//格式为 DataView.Filter = "GZDYMC IN ('job','tree',work')";
string strView = "GZDYMC in (";
int ii = 0;
while(ii < ColTrueNames.Count)
{
strView += "'" + ColTrueNames[ii] + "',";
ii++;
}
strView += "'null')";
thisView.RowFilter = strView;
WebForm3.aspx
在html 页面中只有这一句;
HTML


<%
@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="DataGridPage.WebForm3" %>
C#
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace DataGridPage

{
/**//// <summary>
/// WebForm3 的摘要说明。
/// </summary>
public class WebForm3 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(! this.IsPostBack)
{
SqlConnection conn=new SqlConnection("Server=.;database=pubs;uid=sa;pwd=;");
conn.Open();
SqlDataAdapter com=new SqlDataAdapter("select top 10 * from employee",conn);
DataSet ds=new DataSet();
com.Fill(ds);
string strRSS="";
strRSS = strRSS + "<rss version=\"2.0\"> ";
strRSS = strRSS + "<channel>";
strRSS = strRSS + "<title>*********</title>";
strRSS = strRSS + "<link>http://www.******/unet</link>";
strRSS = strRSS + "<language>zh-cn</language> ";
strRSS = strRSS + "<description>BY UNET</description>";
foreach(DataRow R in ds.Tables[0].Rows)
{
strRSS = strRSS+"<item>";
strRSS = strRSS + "<title>" +R[1]+ "</title>";
strRSS = strRSS + "<link>http://www.****/shownews.aspx?id=" +R[3]+ "</link> ";
strRSS = strRSS + "<description>" +R[0]+ "</description>";
strRSS = strRSS + "</item>";

}
strRSS = strRSS+"</channel>";
strRSS=strRSS+"</rss>";
Response.Write(strRSS);
Response.ContentType="text/xml";
}
}

Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
} if(! this.IsPostBack)
{
string strURL="http://localhost/DataGridPage/WebForm3.aspx";
XmlTextReader reader=new XmlTextReader(strURL);
DataSet ds=new DataSet();
ds.ReadXml(reader);
this.DataGrid1.DataSource=ds.Tables[2];
// this.div.InnerHtml=Server.HtmlDecode(ds.Tables[2].Rows[1]["description"].ToString());
this.DataGrid1.DataBind();
}