listbox parameter in method
How can I pass a listbox datasource to asp.net class method?
Here is how the method is being called:
DataSet DS4DDL1 = mypj.searchPJ(Listbox data???,searchText);
Is is possible? Please modify the开发者_StackOverflow中文版 above line to add the listbox datasource in this method.
You should access your listbox "data source" using the Items property which is of the type ListItemCollection. Your method would look like this:
DataSet DS4DDL1 = mypj.searchPJ(listBox.Items,searchText);
Method: public DataSet searchPJ(ListBox ProjList???, String ProjectName) { DataSet DSToReturn = new DataSet(); //logic to filter based on the column NAme
DataTable results = (from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable()
orderby d.Field<string>("Name") ascending
where d["Name"].ToString().Contains(ProjectName)
select d).CopyToDataTable();
DSToReturn.Tables.Add(results);
return DSToReturn;
}
Calling Method: protected void ProjDDL1_SelectedIndexChanged(object sender, EventArgs e) { String ProjectDDL1 = ProjDDL1.SelectedItem.Text; ClientPJ mypj = new ClientPJ((DataSet)(Session["Client_ProjectDS"])); //DataSet DS4DDL1 = mypj.searchPJ("chemistry"); ListBox listBox = new ListBox(); DataSet DS4DDL1 = mypj.searchPJ(listBox, "chemistry"); //Does not work ProjList.Items.Clear(); foreach (DataRow dr in DS4DDL1.Tables[0].Rows) { //only add item with valid UID if (dr[0].ToString().Trim().Length > 0) //use UID as the item value ProjList.Items.Add(new ListItem(string.Format("{0}", dr[0].ToString()))); }
}
精彩评论