DataTable dt = QueryUtil.GetDataResult(sql);
DataView myDataView = new DataView(dt);
string[] strComuns = { "KIND_ID", "StyleCount" };//此处可加任意数据项组合
dt = myDataView.ToTable(true, strComuns); this.Repeater1.DataSource = dt.DefaultView;
this.Repeater1.DataBind();
在网上找了 中间那三行代码 说是过滤重复数据的。 但是没有用呀 大家帮忙看看 小弟急啊
DataView myDataView = new DataView(dt);
string[] strComuns = { "KIND_ID", "StyleCount" };//此处可加任意数据项组合
dt = myDataView.ToTable(true, strComuns); this.Repeater1.DataSource = dt.DefaultView;
this.Repeater1.DataBind();
在网上找了 中间那三行代码 说是过滤重复数据的。 但是没有用呀 大家帮忙看看 小弟急啊
/// 去除重复行
/// </summary>
/// <param name="dt">DataTable</param>
/// <param name="con">要显示的字段</param>
/// <returns></returns>
public static DataTable ToDistinct(this DataTable dt,string[] con){
return dt.DefaultView.ToTable(true,con);//注:其中ToTable()的第一个参数为是否DISTINCT }
{
ArrayList indexList = new ArrayList();
for (int i = 0; i < ds.Tables[0].Rows.Count-1; i++)
{
if (!IsContain(indexList, i))
{
for (int j = i + 1; j < ds.Tables[0].Rows.Count; j++)
{
if (ds.Tables[0].Rows[i][AccountInfo.Columns.AUName].ToString() == ds.Tables[0].Rows[j][AccountInfo.Columns.AUName].ToString())
{
indexList.Add(j);
}
}
}
}
for (int i = indexList.Count - 1; i >= 0; i--)
{
int index = Convert.ToInt32(indexList[i]);
ds.Tables[0].Rows.RemoveAt(index);
}
}
bool IsContain(ArrayList indexList, int index)
{
for (int i = 0; i < indexList.Count; i++)
{
int tempIndex = Convert.ToInt32(indexList[i]);
if (tempIndex == index)
{
return true;
}
}
return false;
} public DataTable SelectDistinct(DataTable SourceTable, string FieldName)
{
DataTable dt = new DataTable();
for (Int32 i = 0; i < SourceTable.Columns.Count; i++)
{
string fieldName=SourceTable.Columns[i].Caption;
dt.Columns.Add(fieldName, SourceTable.Columns[fieldName].DataType);
}
DataRow dataRow = dt.NewRow();
foreach (DataRow dr in SourceTable.Select("", FieldName))
{
if (dataRow == null || !(ColumnEqual(dataRow[FieldName], dr[FieldName])))
{
dataRow=dr;
DataRow row = dt.NewRow();
for (int i = 0; i < dataRow.ItemArray.Length; i++)
{
row[i] = dataRow[i];
}
dt.Rows.Add(row);
}
}
return dt;
}
参考
//建立临时表 DataTable dt1
ViewState["ID"]="";for(int i=0 ; i<dt.Row.Counts ; i++)
{
if( ViewState["ID"].ToString().IndexOf(""+dt.Row[i]["ID"].ToString()+"") < 0 )
{
ViewState["ID"] += dt.Row[i]["ID"].ToString() + "|"; //dt1中添加dt.Row[i]["ID"]的数据
}
}
two.Sort = "id";
DataTable newTable = two.ToTable(true,"id","key","value");
终于解决了