如何从网格中过滤重复值? [英] How to filter duplicate values from a grid ?
问题描述
我想动态生成网格中的列,我使用了grid.addcolumn属性但
我的代码抛出的错误就像列名已经存在。错误是因为在数据库中使用
的过程返回相同的值。我不能在我的程序中使用''distinct'',因为返回多个字段的程序只需要我需要显示为动态列的字段是重复的。
所以我需要在ASP.net代码中进行一次过滤。
请帮我从过程输出集中选择不同的字段。
I want to generate columns in a grid dynamically, i used grid.addcolumn property but
My code is throwing error like "Column name already exists". The error is because the procedure which am using
in database returning same values. I can''t use ''distinct'' in my procedure because the procedure returning more than one field and only
the field which i need to show as a dynamic column is repeating.
So i need to do one filtering in ASP.net code.
Please please help me to select the distinct fields from the procedure output set.
推荐答案
我想,它会对你有所帮助
i think , it will help you
public DataTable SelectDistinct(DataTable SourceTable, string FieldName)
{
// Create a Datatable datatype same as FieldName
DataTable dt = new DataTable(SourceTable.TableName);
dt.Columns.Add(FieldName, SourceTable.Columns[FieldName].DataType);
// Loop each row & compare each value with one another
// Add it to datatable if the values are mismatch
object LastValue = null;
foreach (DataRow dr in SourceTable.Select("", FieldName))
{
if (LastValue == null || !(ColumnEqual(LastValue,dr[FieldName])))
{
LastValue = dr[FieldName];
dt.Rows.Add(new object[] { LastValue });
}
}
return dt;
}
这篇关于如何从网格中过滤重复值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!