使用mod%2在两个中继器上拆分数据集结果 [英] split dataset results over two repeaters using mod %2

查看:46
本文介绍了使用mod%2在两个中继器上拆分数据集结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在两个转发器之间分割我的数据集的结果,显示左转发器中的所有偶数和右边的奇数索引。到目前为止,我的代码如下:

 CoachFavPlayerProvider coachFavPlayer =  new  CoachFavPlayerProvider(); 
DataSet dataset = coachFavPlayer.CoachFavPlayer(CoachID);

DataTable leftContent = dataset.Tables [ 0 ];
DataTable rightContent = dataset.Tables [ 0 ];

favRepeater.DataSource = rightContent;
favRepeaterRight.DataSource = leftContent;

favRepeaterRight.DataBind();
favRepeater.DataBind();



这显然只是将这一切都绑定到两个中继器上,我不知道我的生活如何分解它。提前致谢! :)

解决方案

在转发到转发器控制的数据源之前过滤数据

 DataTable leftContent = dataset.Tables [ 0 ] 
leftContent.DefaultView.RowFilter = < span class =code-string>(SrNo%2)= 0;

DataTable rightContent = dataset.Tables [ 0 ]
RightContent.DefaultView.RowFilter = (SrNo%2)= 1;







 DataTable leftContent = dataset.Tables [ 0 ]。Clone(); 
for (i = 0 ; i< dataset.Tables [ 0 ]。rows.count / 2; i ++)
{

dtTemp.ImportRow(dataset.Tables [ 0 ]行[1])。
}
DataTable rightContent = dataset.Tables [ 0 ]。克隆();
for (i = dataset.Tables [ 0 ]。rows.count / 2; i< ; dataset.Tables [ 0 ]。rows.count; i ++)
{

dtTemp.ImportRow(dataset.Tables [< span class =code-digit> 0
]。rows [i]);
}





快乐编码!

:)


这是我测试的代码,运行正常。



制作一个独立的方法来过滤记录



  private  DataTable GetFilteredData(DataTable sourceDataTable, string  columnName, string   value 
{
DataTable dtTemp = sourceDataTable.Clone( );
DataRow [] result = sourceDataTable.Select(columnName + =' + value + ');
foreach (DataRow行 结果)
{

dtTemp.ImportRow(row);
}
return dtTemp;
}





之后调用此方法进入你的函数



 CoachFavPlayerProvider coachFavPlayer =  new  CoachFavPlayerProvider(); 
DataSet dataset = coachFavPlayer.CoachFavPlayer(CoachID);

DataTable leftContent = GetFilteredData(dataset.Tables [ 0 ], < span class =code-string>(SrNo%2), 0);
DataTable rightContent = GetFilteredData(dataset.Tables [ 0 ], (SrNo%2) 1);

favRepeater.DataSource = rightContent;
favRepeaterRight.DataSource = leftContent;

favRepeaterRight.DataBind();
favRepeater.DataBind();





希望这会对你有帮助。


您可以使用选择 [ ^ ]过滤DataTable的功能。查看示例:

 DataRow [] dr1 = dataset.Tables [ 0 ]。选择( (ColumnName%2)= 0); 
DataTable dt1 = dr1.CopyToDataTable();

DataRow [] dr2 = dataset.Tables [ 0 ]。选择( (ColumnName%2)= 1);
DataTable dt2 = dr2.CopyToDataTable();



然后你可以设置转发器控制的数据源。见:

 favRepeater.DataSource = dt1; 
favRepeaterRight.DataSource = dt2;

favRepeaterRight.DataBind();
favRepeater.DataBind();





我希望你理解解决方案。

- 阿米特

im trying to split the results of my dataset between two repeaters, displaying all the even in the left repeater and the odd index in the right. so far my code is as follows.

CoachFavPlayerProvider coachFavPlayer = new CoachFavPlayerProvider();
DataSet dataset = coachFavPlayer.CoachFavPlayer(CoachID);

DataTable leftContent = dataset.Tables[0];
DataTable rightContent = dataset.Tables[0]; 
    
favRepeater.DataSource = rightContent;
favRepeaterRight.DataSource = leftContent;

favRepeaterRight.DataBind();
favRepeater.DataBind();


this obviously just binds the whole lot to both repeaters, and i cant for the life of me figure out how to split it. thanks in advance! :)

解决方案

filter datatbles before assin to datasource of repeater control

 DataTable leftContent = dataset.Tables[0]
leftContent.DefaultView.RowFilter = "(SrNo % 2) = 0";
 
 DataTable rightContent = dataset.Tables[0]
RightContent.DefaultView.RowFilter = "(SrNo % 2) = 1";



or

DataTable leftContent = dataset.Tables[0].Clone();
           for(i=0;i<dataset.Tables[0].rows.count/2 ; i++)
           {

               dtTemp.ImportRow(dataset.Tables[0].rows[i]);
           }
DataTable rightContent = dataset.Tables[0].Clone();
           for(i=dataset.Tables[0].rows.count/2;i<dataset.Tables[0].rows.count ; i++)
           {

               dtTemp.ImportRow(dataset.Tables[0].rows[i]);
           }



Happy Coding!
:)


Here is the code tested by me and running fine.

Make a independent method to filter records as

private DataTable GetFilteredData(DataTable sourceDataTable, string columnName, string value)
 {
     DataTable dtTemp = sourceDataTable.Clone();
     DataRow[] result = sourceDataTable.Select(columnName + " = '" + value + "'");
     foreach (DataRow row in result)
     {

         dtTemp.ImportRow(row);
     }
     return dtTemp;
 }



After this call this method into your function as

CoachFavPlayerProvider coachFavPlayer = new CoachFavPlayerProvider();
DataSet dataset = coachFavPlayer.CoachFavPlayer(CoachID);
 
DataTable leftContent = GetFilteredData(dataset.Tables[0],"(SrNo % 2)","0");
DataTable rightContent = GetFilteredData(dataset.Tables[0],"(SrNo % 2)","1");

favRepeater.DataSource = rightContent;
favRepeaterRight.DataSource = leftContent;
 
favRepeaterRight.DataBind();
favRepeater.DataBind();



Hope this will help you.


You can use Select[^] function to filter your DataTable. See an example:

DataRow[] dr1 = dataset.Tables[0].Select("(ColumnName % 2) = 0");
DataTable dt1 = dr1.CopyToDataTable();

DataRow[] dr2 = dataset.Tables[0].Select("(ColumnName % 2) = 1");
DataTable dt2 = dr2.CopyToDataTable();


And then you can set the datasource of repeater control. See this:

favRepeater.DataSource = dt1;
favRepeaterRight.DataSource = dt2;

favRepeaterRight.DataBind();
favRepeater.DataBind();



I hope you understood the solution.

--Amit


这篇关于使用mod%2在两个中继器上拆分数据集结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆