在客户端过滤数据集 [英] Filtering Dataset in client side

查看:59
本文介绍了在客户端过滤数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由Web服务返回的数据集...现在,我想根据客户端的dropdownlist对其进行过滤..客户端不知道表或列的名称...

例如,
webservice返回书籍列表及其详细信息作为数据集,在客户端,我想从下拉列表中选择特定书籍的详细信息.并在gridview中显示过滤后的值

按照我的逻辑..
我有一个.asmx页面,返回的数据集包含该书的详细信息...其中包括书名,作者出版者,价格等...

然后在.aspx页(客户端)中获取该数据集...然后,当用户从下拉列表中选择书名时,仅必须显示特定的书详细信息....

此外,客户端不知道数据表名称或主键外键详细信息..他所拥有的只是数据集..他必须搜索特定的行..


我该如何进行?请尽快帮助我..

I have a data set which is returned by the webservice... Now i want to filter it based on the dropdownlist in the client side.. client not knowing the table or column name...

For example take,
webservice returning the list of books and its details as dataset , At client side i want to select the details of particular book choosen from the drop down list.. And display the filtered value in the gridview

Here in my logic..
I have a .asmx page returning a dataset containing the details of the book... which includes book name,author publisher,price etc etc...

Then in .aspx page (client side) am getting that dataset... then when a user choose the book name from the dropdown list the particular book details alone has to be displayed....

Moreover the client doesnt know the data table name or primarykey foreign key details.... All he have is the dataset..He got to search the specific row..


how can i proceed? Kindly help me as soon as possible..

推荐答案

DataSet   ds = dropdown.DataSource;
DataTable dt = ds.Tables[0];
DataRow   dr = dt.Rows[dropdown.SelectedIndex];



此时,您具有选定项目的绑定数据行,并且可以访问该行中的所有列.

编辑===============

要过滤数据集,请使用linq.继续前面的示例:



At this point, you have the bound data row for the selected item, and you can get to all the columns in the row.

EDIT ===============

To filter the dataset, use linq. Continuing with my previous example:

DataTable dt2 = (from item in dt.AsEnumerable()
                 where Convert.ToString(item["columnname"]) == "123"
                 select item).CopyToDataTable();


您可以使用此..
You Can Use this..
<pre lang="c#">
For(i=0;i<dataset.table[0].rows.count;i++)>
{
if(dataset.Table[0].Rows[i]["Coloum Name"]==dropdown.Text)
{
DataSet ds=new DataSet();
DataRow dr=new DataRow();
//here fill the value of dataset row into this row "dr" and add this row to new dataset ds you can get the filtered data into new data set "ds"
}
}


这篇关于在客户端过滤数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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