Click here to Skip to main content
15,559,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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..
Posted
Updated 7-Aug-11 8:27am
v3

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


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:

C#
DataTable dt2 = (from item in dt.AsEnumerable()
                 where Convert.ToString(item["columnname"]) == "123"
                 select item).CopyToDataTable();
 
Share this answer
 
v2
Comments
Manjari Anand 7-Aug-11 8:08am    
Thank you john....
But what i actually want is i want to filter the dataset which is returned by the webservice... according to the value choosen in the dropdownlist and display them..
#realJSOP 7-Aug-11 13:50pm    
See my updated answer.
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"
}
}
 
Share this answer
 
Comments
Manjari Anand 7-Aug-11 9:07am    
Unintended reference comparison on this line

if(data.Tables[0].Rows[i]["Coloum Name"]==DropDownList1.SelectedValue)

Moreover being client side...Am not able to mention the column name
Manjari Anand 7-Aug-11 9:10am    
I want to filter a specific row from the dataset returned by the server.. and display it...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900