Question

Asp.net 3.5 class

Asked by: suran78

Experts,

I need immediate help.  I have to create a class in asp.net 3.5.  This class will take a dataset as input and have method in it that will populate dropdown list.  The dataset has 5 columns.  Based on column number passed as parameter to this method, the dropdown list will be populated with data in that column.

Please help me with code ASAP.  

Thanks.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-12 at 14:55:44ID24806130
Topic

Programming for ASP.NET

Participating Experts
1
Points
500
Comments
68

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Filtering a dataset through dropdown
    I recently posted this question before, but the solution kindly provided by expert bsdotnet did not work after all. I pretty much tried tweaking every single bit of code, but nothing seemed to work. (I must admit I am not a asp.net hand-coder, so that explains.. ;) Here is a...
  2. Populate Dropdown in Detailsview
    I've been struggling with this for two days. PLEASE HELP! In my Detailsview used to add records, I have two dropdown boxes that together determine the contents of the third dropdown. I'm getting the correct dataset back from my database, but I cannot get the dropdown popul...
  3. Populating a Dropdown list
    I have three Dropdown lists. The second and third Dropdown lists are populated basing on the selected itetm in the previous Dropdown list. I use the SelectedIndexChanged procedure to populate the Dropdown lists. It so happens that when there is only one item in the previus Dr...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: suran78Posted on 2009-10-12 at 15:15:00ID: 25555549

here is the public method, how do I add linq code in it that will retrieve data based on column name

#region Public Methods

    public DataSet DDLPopulate(String columnName)
    {
        DataSet DSToReturn = new DataSet();
        //logic to filter based on the column NAme
        return DSToReturn;
    }

 

by: burakiewiczPosted on 2009-10-13 at 08:39:50ID: 25561130

are you trying to return all of the information from a specific column or filter based on a column
you can just do a select
ds.Tables[0].Select(columnname "= some value");

 

by: burakiewiczPosted on 2009-10-13 at 08:42:31ID: 25561158

 

by: suran78Posted on 2009-10-13 at 08:47:40ID: 25561195

DataTable filteredCCenter = (from d in ((DataSet)_MyDataset).???????

        DSToReturn.Tables.Add(filteredCostCenter);
        return DSToReturn;

I have to use linq query.  what wil be the syntax in ???? - such that distinct values from dataset column name "business" is extracted to the datatable.  Please provide the linq query code.

 

by: suran78Posted on 2009-10-13 at 08:50:36ID: 25561236

Actually the column name is passed to the class method as parameter like this :

project mypj = new project((DataSet)(Session["Client_ProjectDS"]));
                DataSet DS4DDL1 = mypj.DDLPopulate("Business");
So what should be the linq query :
public DataSet DDLPopulate(String columnName)
    {
        DataSet DSToReturn = new DataSet();
        DataTable filteredCCenter = (from d in ((DataSet)_MyDataset).???????

        DSToReturn.Tables.Add(filteredCostCenter);
   
        return DSToReturn;
    }

 

by: burakiewiczPosted on 2009-10-13 at 09:12:38ID: 25561451

 IEnumerable<string> query = (IEnumerable<string>)(from d in dt.AsEnumerable()
                                select d["business"]
                         ).Distinct();
            foreach (string s in query)
            {
                //add to a datatable
            }

            //then return

 

by: suran78Posted on 2009-10-13 at 09:13:14ID: 25561460

Ok so I got the linq query done and its working except one small problem, I am hardcoding the columnName.  How do I pass the parameter colunName to the linq query instead of  hardcoding "Business"???

DataTable filteredCostCenter = (from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable()
                                        where (d.Field<string>("Business") != null )
                                        select d).Distinct().CopyToDataTable();

 

by: burakiewiczPosted on 2009-10-13 at 09:15:11ID: 25561484

this would also work for the query
 var query =(from d in dt.AsEnumerable()
                                select d.Field<string>("business")).Distinct();


            var query1 =(from d in dt.AsEnumerable()
                                select d["business"]).Distinct();

 

by: burakiewiczPosted on 2009-10-13 at 09:15:53ID: 25561494

just put the variable name instead of the hardcoded column

 

by: suran78Posted on 2009-10-13 at 09:17:16ID: 25561506

yes, this work as expected: Thx

DataTable filteredCostCenter = (from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable()
                                        where (d.Field<string>(columnName) != null)
                                        select d).Distinct().CopyToDataTable();

 

by: burakiewiczPosted on 2009-10-13 at 09:18:14ID: 25561513

with your query, i think you will get distinct rows, but not distinct column values

 

by: suran78Posted on 2009-10-13 at 09:24:29ID: 25561569

yes, which mean that if business column has 3 distinct data/values - Bus1, bus2, bus3, then all those values will show up in DDL.  How can I add in CS code behind in ProjDDL1.DataValueField = "Business";
number that increases 1, 2, 3,  dynamically with the number of business values?

ClientPJ mypj = new ClientPJ((DataSet)(Session["Client_ProjectDS"]));
                DataSet DS4DDL1 = mypj.DDLPopulate("Business");

                ProjDDL1.DataSource = DS4DDL1;
                ProjDDL1.DataTextField = "Business";
                ProjDDL1.DataValueField = "Business";
                ProjDDL1.DataBind();
                ProjDDL1.Items.Insert(0, "--");

 

by: burakiewiczPosted on 2009-10-13 at 09:29:48ID: 25561625

but if say you have 3 columns
and you have values (1,2,bus1) (2,3,bus2) (3,4,bus3) (5,6,bus1)
you will get back bus1,bus2,bus3,bus1

add this after the where but before the select
 orderby d[columnName] ascending

 

by: suran78Posted on 2009-10-13 at 09:45:38ID: 25561765

After some testing I found out that the values are not distinct  - what is wrong with the linq query, distinct()?
DataTable filteredCostCenter = (from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable()
                                        where (d.Field<string>(columnName) != null)
                                        select d).Distinct().CopyToDataTable();

 

by: burakiewiczPosted on 2009-10-13 at 09:59:10ID: 25561893

Nothing. Like I said u will get distinct rows not column values unless u use one of the queries I gave u I saw an example that did it with a group by lll find it

 

by: burakiewiczPosted on 2009-10-13 at 10:13:02ID: 25562019

this might work

DataTable results = (from d in dt.AsEnumerable()
                                    orderby  d[columnName] ascending
                                    group d by d[columnName] 
                                    into g 
                                    select g.First()).CopyToDataTable();

                                              
1:
2:
3:
4:
5:

Select allOpen in new window

 

by: suran78Posted on 2009-10-13 at 12:16:39ID: 25563343

Yes, initially it gave me error but I added the where clause and its working now, I am getting unique values from column

DataTable filteredCostCenter = (from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable()
                                        where (d.Field<string>(columnName) != null)
                                        orderby d[columnName] ascending
                                        group d by d[columnName]
                                            into g
                                            select g.First()).CopyToDataTable();

 

by: suran78Posted on 2009-10-13 at 12:54:05ID: 25563750

I have to add another method in this class to search for matching text selected in any of the DDL or text box in another field in same dataset.  Have to use ling query:
 public DataSet searchPJ(String ProjectName)
    {
        DataSet DSToReturn = new DataSet();
        //linq query to filter Project column based on search string selected in DDL or textbox
     
        return DSToReturn;
    }

 

by: suran78Posted on 2009-10-13 at 12:59:09ID: 25563819

can Jquery help?  Any idea? also should I open another question for this search?  Thanks a lot for helping with the distinct linq Query.  

 

by: burakiewiczPosted on 2009-10-13 at 13:02:33ID: 25563862

do you need distinct values again? if not
DataTable results = from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable()
                                 orderby d.Field<string>("Project") ascending
                                 where d["Project"].ToString().Equals(ProjectName)
                                 select d).CopyToDataTable();

if you dont care about case

 DataTable results = (from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable()
                                orderby d.Field<string>("Project") ascending
                                 where d["Project"].ToString().Equals(ProjectName, StringComparison.CurrentCultureIgnoreCase )
                                 select d).CopyToDataTable();

 

by: burakiewiczPosted on 2009-10-13 at 13:03:09ID: 25563870

not sure about jquery

 

by: suran78Posted on 2009-10-13 at 13:59:34ID: 25564588

onselect change event for dropdownlist, the selected text is passed to search method.  But nothing is happening.  - something wrong with the string that I am passing?
DataSet DS4DDL1 = mypj.searchPJ("ProjectDDL1");
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("ProjectDDL1");
        ProjList.Items.Clear();
        foreach (DataRow dr in DS4DDL1.Tables[0].Rows)
        {
           
            if (dr[0].ToString().Trim().Length > 0)
               
                ProjList.Items.Add(new ListItem(string.Format("{0}", dr[0].ToString())));
        }

    }

 

by: suran78Posted on 2009-10-13 at 14:13:14ID: 25564789

Can this query seek partial search string in dataset?  DDL selection has substring not full project name.  So user selects teh substring in DDL and the listbox gets filtered with matching proj name.  

 

by: burakiewiczPosted on 2009-10-13 at 14:17:12ID: 25564834

just change the Equals in my query to one of these :Containts,StartsWith, or EndsWith or IndexOf >-1

 

by: suran78Posted on 2009-10-13 at 14:24:55ID: 25564930

I am using this one and its giving syntax error when I tried replacing equlas to contains.
DataTable results = (from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable()
                                orderby d.Field<string>("Project") ascending
                                 where d["Project"].ToString().Contains(ProjectName, StringComparison.CurrentCultureIgnoreCase )
                                 select d).CopyToDataTable();

 

by: burakiewiczPosted on 2009-10-13 at 14:26:31ID: 25564947

contains only takes 1 argument remove the ,StringComparison.CurrentCultureIgnoreCase

 

by: suran78Posted on 2009-10-13 at 15:03:48ID: 25565300

If the serach does not return any result I am getting a compilation error.  How can I check for empty dataset?
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();

 

by: suran78Posted on 2009-10-13 at 15:06:09ID: 25565320

also I have to add the ignorecase in contains.  

 

by: suran78Posted on 2009-10-14 at 05:52:35ID: 25569863

How can I pass listbox datasource to the method:


        DataSet DS4DDL1 = mypj.searchPJ(listboxdatasource, searchText);

 

by: burakiewiczPosted on 2009-10-14 at 06:34:17ID: 25570251

just check if the dataset==null or the dataset.table["TableName"]==null

2 ways to do the ignore case
DataTable results = (from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable()
                             orderby d.Field<string>("Name") ascending
                             where d["Name"].ToString().ToLower().Contains(ProjectName.ToLower())
                             select d).CopyToDataTable();

or

DataTable results = (from d in ((DataSet)_MyDataset).Tables["Records"].AsEnumerable()
                             orderby d.Field<string>("Name") ascending
                             where d["Name"].ToString().IndexOf("", ProjectName.CurrentCultureIgnoreCase)>-1
                             select d).CopyToDataTable();

3rd if you know the type you can just type it in the method like

public DataSet searchPJ(DataSet ds,String ProjectName)
or
public DataSet searchPJ(DataTable dt,String ProjectName)

if not
public DataSet searchPJ(object source,String ProjectName)
and then you would have to check its type and then do something with it

 

by: suran78Posted on 2009-10-14 at 06:59:55ID: 25570531

I tried it this way and the datasource that I am passing is null, even though it not null:  How can I pass datasource to this method?
public DataSet searchPJ(DataSet listb, String ProjectName)
    {
        DataSet DSToReturn = new DataSet();
        //logic to filter based on the column NAme
        DataTable results = (from d in ((DataSet)listb).Tables["Records"].AsEnumerable()
                             orderby d.Field<string>("Name") ascending
                             where d["Name"].ToString().Contains(ProjectName)
                             select d).CopyToDataTable();
           
        DSToReturn.Tables.Add(results);
        return DSToReturn;
    }
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((DataSet)(DDLProjectAssociation.DataSource), "chemistry");
        DataSet DS4DDL1 = mypj.searchPJ((DataSet)(ProjList.DataSource), "chemistry");
        ProjList.Items.Clear();
        foreach (DataRow dr in DS4DDL1.Tables[0].Rows)
        {
                if (dr[0].ToString().Trim().Length > 0)
               ProjList.Items.Add(new ListItem(string.Format("{0}", dr[0].ToString())));
        }

    }

 

by: burakiewiczPosted on 2009-10-14 at 07:18:58ID: 25570755

if the listbox's databind is not called before you try this
public DataSet searchPJ(DataSet listb, String ProjectName)
it will show up as null, since it doesnt have a datasource anymore, it is just reading the values from viewstate

 

by: burakiewiczPosted on 2009-10-14 at 07:20:03ID: 25570771

also it looks like in your method you are just adding the items and not actually binding them, so there is no datasource

 

by: suran78Posted on 2009-10-14 at 07:28:32ID: 25570876

Method should do this I don't know what the code wil be- Please help

protected void ProjDDL1_SelectedIndexChanged(object sender, EventArgs e)
    {
        String SearchStr = ProjDDL1.SelectedItem.Text;
        // Code to get the listbox ProjList datasource?

        ClientPJ mypj = new ClientPJ((DataSet)(Session["Client_ProjectDS"]));
       
        DataSet DS4DDL1 = mypj.searchPJ((DataSet)(ProjListDataSource???), SearchStr);
       
        ProjList.Items.Clear();
       // Code to check if not Null then update the listbox or databind the list box with the search results?
        foreach (DataRow dr in DS4DDL1.Tables[0].Rows)
        {
                       if (dr[0].ToString().Trim().Length > 0)
                        ProjList.Items.Add(new ListItem(string.Format("{0}", dr[0].ToString())));
        }

    }

 

by: burakiewiczPosted on 2009-10-14 at 07:36:20ID: 25570970

wouldnt the source be the items from this ?
((DataSet)(Session["Client_ProjectDS"])

 

by: suran78Posted on 2009-10-14 at 07:41:17ID: 25571025

yes, only on page load, but after that when 1st dropdown selects the listbox will filter when the 2nd DDL will select the 1st DDL's filtered listbox datasource will be passed. there are 5 DDLs and there is no sequence on DDL selection, i.e. user can select from 4th or 2nd and then select from 3 or 5th, the listbox item will remember the previous filter.  So that's why I am trying to pass the listbox datasource to the method for searching.

 

by: burakiewiczPosted on 2009-10-14 at 07:43:33ID: 25571052

you could also store the filtered dataset in session

 

by: suran78Posted on 2009-10-14 at 08:00:00ID: 25571285

Sadly, that is not accepted, becaz it wil slow the performance, and this prosal of mine was turned down.

So coming back to the same old problem,  I am passing list items instead of source now.
DataSet DS4DDL1 = mypj.searchPJ(ProjList.Items, "*Prefunded");

But in method getting stucked on linq query to search listcollection litems, any idea how to search list colltection? :
 public DataSet searchPJ(ListItemCollection projList, String ProjectName)
    {
        DataSet DSToReturn = new DataSet();
               DataTable results = (from d in (projList.????
                             orderby d.Field<string>("Name") ascending
                             where d["Name"].ToString().Contains(ProjectName)
                             select d).CopyToDataTable();
        select d).CopyToDataTable();
        DSToReturn.Tables.Add(results);
        return DSToReturn;
    }

 

by: suran78Posted on 2009-10-14 at 08:28:22ID: 25571667

Is it possible to convert ListItemCollection to dataset?

 

by: burakiewiczPosted on 2009-10-14 at 08:32:28ID: 25571722

all you will get back is a list item
but you can do
 ListItem item = projList.FindByText("ProjectName");
or
 ListItem item = projList.FindByValue("ProjectName");

 

by: suran78Posted on 2009-10-14 at 08:35:44ID: 25571771

So if there are more than 1 match the listItem Item will have all of them.  If that works then how can I databind the listbox with his set of filtered items?

 

by: suran78Posted on 2009-10-14 at 08:39:10ID: 25571800

This won't work, becaz it does not allow partial search.  This method does not do partial searches or wildcard searches

 

by: burakiewiczPosted on 2009-10-14 at 08:47:18ID: 25571894

ListItemCollection returnItems= new ListItemCollection();
             foreach (ListItem item in projList)
             {
                 if (item.Text.IndexOf(projectname, StringComparison.CurrentCultureIgnoreCase)>-1
                 {
                     returnItems.Add(item);
                 }
             }

            return returnItems;

 

by: suran78Posted on 2009-10-14 at 08:48:04ID: 25571897

OK< so coming back again - is there any way i can store listitemcollection to dataset or datatable?

 

by: suran78Posted on 2009-10-14 at 08:51:51ID: 25571937

On return returnItems;  I am getting error - cannot convert to dataset.

 

by: burakiewiczPosted on 2009-10-14 at 08:57:18ID: 25571990

you would have to change the return type to ListItemCollection
dataset or tables are for data so you would have to loop through the items and create the rows and values

 

by: suran78Posted on 2009-10-14 at 09:03:54ID: 25572072

I changed it to
public ListItemCollection searchPJ(ListItemCollection projList, String ProjectName)

But how to I display or bind the returned collection to listbox?
ListItemCollection DS4DDL1 = mypj.searchPJ(ProjList.Items, "*Prefunded");
ProjList.Items.Clear();
ProjList.bind??

 

by: burakiewiczPosted on 2009-10-14 at 09:08:58ID: 25572119

ProjList.Datasource=DS4DDL1;
ProjList.Databind()
or loop throught the collection and add them

 

by: suran78Posted on 2009-10-14 at 09:13:36ID: 25572163

Maybe it just something small I am missing:
error
  Message="DataBinding: 'System.Web.UI.WebControls.ListItem' does not contain a property with the name 'Name'."

Listbox has name and value.
 

 

by: burakiewiczPosted on 2009-10-14 at 09:16:22ID: 25572192

Text and Value for the items

 

by: suran78Posted on 2009-10-14 at 09:20:26ID: 25572237

When I am bind listbox in pagload
ProjList.DataSource = DS4DDL1;
        ProjList.DataTextField = "Name";
        ProjList.DataValueField = "Value";
        ProjList.DataBind();

When I am rebinding it again with seacrh results -
ProjList.DataSource = DS4DDL1;
        ProjList.DataTextField = "Name";
        ProjList.DataValueField = "Value";
        ProjList.DataBind(); <---- giving error - does not contain property with name "Name"
What is missing here?

 

by: suran78Posted on 2009-10-14 at 09:22:04ID: 25572257

Does that mean in function search, something needs to be added to include the name and value properties in Listbox collection being returned?

istItemCollection returnItems= new ListItemCollection();
             foreach (ListItem item in projList)
             {
                 if (item.Text.IndexOf(ProjectName, StringComparison.CurrentCultureIgnoreCase)>-1)
                 {
                     returnItems.Add(item);
                 }
             }

            return returnItems;

 

by: burakiewiczPosted on 2009-10-14 at 09:22:17ID: 25572261

ProjList.DataTextField = "Text";
        ProjList.DataValueField = "Value";

 

by: burakiewiczPosted on 2009-10-14 at 09:24:27ID: 25572291

if you are using the same bind, you will need to create a datatable with name and value columns and create the rows.  you can also create and extension method for the listitem called name, but those would ahve to be in a new question

 

by: suran78Posted on 2009-10-14 at 09:33:21ID: 25572386

I think that will be fair to open a new question.  Please reply to the new thread because you have help me all thru this question and are familiar with this it.  

Before I open a new questu=ion, need some help in understanding what is diffrence between
ProjList.DataTextField = "Text";
        ProjList.DataTextField = "Name";
Name is a field in dataset that binds the list box in pageload.  Does this mean that when it rebinded after search listbox does not have Name and Valueids in it?  

 

by: burakiewiczPosted on 2009-10-14 at 09:36:38ID: 25572420

that is because you datatable most likely has columns named name and value.

a listitem only has properties that are Text and Value so you cant bind to Name if it has no Name property

 

by: burakiewiczPosted on 2009-10-14 at 09:42:06ID: 25572471

post the link in this question

 

by: suran78Posted on 2009-10-14 at 09:44:35ID: 25572495

Just trying to see if we don't have to go thru datatable route:

if listitem has text and value, then is it possible to assign value to the rebinded listbox with original value coming from session variable dataset?  if that is possible, then I only need this value id.  While text wil display the filtered matching item in listbox, values of these items will be the value id passed in original dataset.  the selected value in listbox will be needed on page submit.  Is it possible to reatin the value at least in listbox?

 

by: suran78Posted on 2009-10-14 at 09:46:25ID: 25572504

Can teh original valueid can be added to listbox item being returned after search?
if (item.Text.IndexOf(ProjectName, StringComparison.CurrentCultureIgnoreCase)>-1)
                 {
                     returnItems.Add(item);
                    // add valueid to listitem
                 }

 

by: burakiewiczPosted on 2009-10-14 at 09:47:35ID: 25572512

try this for the method i dont have much time left for today
 public DataTable searchPJ(ListItemCollection projList, String ProjectName)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Name");
            dt.Columns.Add("Value");

            foreach (ListItem item in projList)
            {
                if (item.Text.IndexOf(ProjectName, StringComparison.CurrentCultureIgnoreCase) > -1)
                {
                    DataRow dr = dt.NewRow();
                    dr["Name"] = item.Text;
                    dr["Value"] = item.Value;
                    dt.Rows.Add(dr);
                }
            }
            return dt;
        }

 

by: suran78Posted on 2009-10-14 at 10:04:41ID: 25572649

I checked the view source and looks like its retaining the values.  That great!!!  
This not the end though, I wil post another qustion and provide link in this one.  Thx :)

 

by: suran78Posted on 2009-10-15 at 07:35:59ID: 25580944

I have posted a question at
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_24814965.html
I will keep this question open for a while, just incase something needs to change.  But overall it was a very helpful solution.  Thx.

 

by: suran78Posted on 2009-10-15 at 12:37:46ID: 25583956

Ran into a serious problem today with the listbox search.  there are 2 dropdown out of 5 that will not search for matching text in listbox but in the dataset behind it, when matching text is found it will populate listbox with dataset.  this filtered dataset wil be ssearched by other DDL as well.  Should I open another question, becaz this solution will not work :(.  Need help ASAP.

 

by: burakiewiczPosted on 2009-10-15 at 12:56:31ID: 25584161

sounds like you need more than one search method since not all of them are searching on the same criteria go ahead and open a new question because that is something different

 

by: suran78Posted on 2009-10-15 at 13:41:23ID: 25584680

Please help, I am in seroius time crunch now, I thought the problem was solve, now coming back to zero again. http://www.experts-exchange.com/Programming/Languages/.NET/Q_24816360.html

 

by: suran78Posted on 2009-10-15 at 14:21:37ID: 25585040

The problem would have been solved if listbox datasource can be passed and searced in webmethod.  Is it possible?

 

by: suran78Posted on 2009-10-16 at 06:31:59ID: 25589313

Is this possible to get valueid from this matching list items and then search data from original dataset? For example in the code :
 public DataSet searchPJ(ListItemCollection projList, String ProjectName)
    {
        DataSet DSToReturn = new DataSet();
        //ListItem item = projList.FindByText("ProjectName");
        ListItemCollection returnItems = new ListItemCollection();
        foreach (ListItem item in projList)
        {
            if (item.Text.IndexOf(ProjectName, StringComparison.CurrentCultureIgnoreCase) > -1)
            {
                returnItems.Add(item); <-----------how can I get valueIDs from listbox with the matching selection instead of text?
// then linq query to search these valueids in dataset _mydataset, extract field name Client_owner and return text value to listbox from dataset field "Name".
dataset structure is :
//Name       Client_owner      Business_owner

           }
        }

        return returnItems;
               
    }

Please help asap. Thx.

 

by: suran78Posted on 2009-10-28 at 07:14:42ID: 25683416

I have posted a new question, please help me if you can

http://www.experts-exchange.com/Programming/Languages/.NET/LINQ/Q_24850922.html

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...