Solved, c#, <List>

Posted on 2012-09-20
Last Modified: 2012-09-26
I have the follwing list in c#
How can I call by using

Basically, if  the List is not null then I want to call just like

response.write data + chr(13)
Question by:solution1368
    LVL 25

    Expert Comment

    by:Luis Pérez
    Please, can you explain your problem better?
    LVL 11

    Expert Comment

    The short answer is that I don't think there is a built-in way to do it exactly like you're thinking. As far as I'm aware there is no "dump"-like method on the Collection or IEnumerable types.

    You can, however, write a short and simple output method. If you want to mimic the behavior you originally wanted, you'll need to slightly extend your DataLibs class by adding another method. Please note that this new method isn't necessary; the code it will contain could be in the output method I mentioned above.

    The new method in DataLibs:
    public string DisplayData(int recordNumberToShow) 
        // note: the recordNumberToShow parameter is optional.
        // just be sure to get rid of line #6 if you don't use it.
        var sb = new StringBuilder();
        sb.AppendFormat("{0}. ", recordNumberToShow.ToString("0000"));
        sb.AppendFormat("InventoryQty = {0}, ", InventoryQty);
        sb.AppendFormat("InventoryDes = {0}, ", InventoryDes);
        sb.AppendFormat("InventoryItemSize = {0}, ", InventoryItemSize);
        sb.AppendFormat("InventoryEquipValue = {0}", InventoryEquipValue);
        return sb.ToString();

    Open in new window

    ... and the new Output method:
    public string DisplayInventoryFor(List<DataLibs> data) 
        var sb = new StringBuilder();
        var counter = 0;
        foreach (var item in data)
            sb.AppendFormat("{0}{1}", item.DisplayData(counter), Environment.NewLine);
        return sb.ToString();

    Open in new window

    ... and with that, you can do this:
    // assuming that "data" is the result of GetInventoryListInflatable()
    Response.Write(DisplayInventoryFor(data) + Environment.NewLine);

    Open in new window


    Author Comment

    Just sample as follow: I can use gridview to bind. It worked, but in my case, I can use gridview because I need to import the data into text file.
    in the case, how can get the data from the objService.GetInventoryListInflatable(datalibs)?

                InsuranceServices.DataLibs datalibs = new Insurance.InsuranceServices.DataLibs();
                datalibs.SessionString = "kudm0aab5kdn3r45mdlpfs2t1";
                Test.DataSource = objService.GetInventoryListInflatable(datalibs);
    LVL 11

    Accepted Solution

    I'll say it again to be clear: There is no built-in "dump" method which will display the data contained within the output. You need to roll your own, something similar to what I provided above, to do this.

    Even with the sample you've shown the same situation applies. Long story short, the output from objService.GetInventoryListInflatable(datalibs) is an IEnumerable... which you have to parse that output to get the results you want.

    Author Closing Comment

    detailed explanation

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now