[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 459
  • Last Modified:

asp.net, c#, <List>

I have the follwing list in c#
How can I call by using asp.net/c#?

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

response.write data + chr(13)
x.txt
0
solution1368
Asked:
solution1368
  • 2
  • 2
1 Solution
 
Luis PérezSoftware Architect in .NetCommented:
Please, can you explain your problem better?
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
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)
    {
        counter++;
        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

0
 
solution1368Author Commented:
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);
            Test.DataBind();
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
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.
0
 
solution1368Author Commented:
detailed explanation
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now