12-09-2011، 11:32 PM
در کل برای sort کردن باید به این روش عمل کنید من یه سمپل براتون میزارم :
کد:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sqlQuery = "SELECT * from Table1" ;
SqlConnection conn = new SqlConnection (ConfigurationManager.AppSettings["ConnectionString"]);
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, conn);
DataTable dtData = new DataTable();
sda.Fill(dtData);
gvResults.DataSource = dtData.DefaultView;
gvResults.DataBind();
}
}
protected void btnFiltering_Click( object sender, EventArgs e)
{
string sqlQuery = "SELECT * from Table1";
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
SqlDataAdapter sda = new SqlDataAdapter (sqlQuery, conn);
DataTable dtData = new DataTable ();
sda.Fill(dtData);
DataView dvData = new DataView(dtData);
dvData.RowFilter = "state = '" + txtFilter.Text.ToUpper() + "'";
gvFilter.DataSource = dvData;
gvFilter.DataBind();
}
protected void btnSorting_Click( object sender, EventArgs e)
{
string sqlQuery = "SELECT * from Table1";
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, conn);
DataTable dtData = new DataTable();
sda.Fill(dtData);
DataView dvData = new DataView(dtData);
dvData.Sort = "city";
gvSort.DataSource = dvData;
gvSort.DataBind();
}
}
گروه دور همی پارسی کدرز
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg