Click here to Skip to main content
15,906,106 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
i do have a requirement that to retrive data which is available in the form of ienumerable<someclassname>, in that i am getting 5 rows of data, from them i need to bind 1st row values to some asp.net textboxes, and 2nd row values to some other textboxes, and 3rd row values to some other.
for that i have written the code as follows.

i am getting the required data from businessclass library in the form of "ienumerable<benefeciarydetails>" type.

Ienumerable<beneficiarydetails>[] requireddata=new Ienumerable<beneficiarydetails>[] { getBeneficiarydetails()};

so, here to treive and assigning data to required textboxes i have written as follows.

for(var i=0;i<requireddata.length;i++){>
if(i==0){
txtlname.text=requireddata[i].lastname;
txtmiddlename.text=requiredata[i].middlename;
}
if(i==1){
txtlnamesecond.text=requireddata[i].lastname;
txtmiddlenamesecond.text=requireddata[i].middlename;
}
if(i==2){
txtlnamethird.text=requrieddata[i].lastname;
txtmiddlenamethired.text=requireddata[i].middlename;
}
.
.
.
.
}

here if the requireddata contains only one row then i need to assign those data to 1st required textboxes. and for all empty will be placed. i have tried above code, but not getting proper result, plz help me to solve this, or should i change my code.
Posted
Updated 9-Feb-15 6:27am

1 solution

The problem is that you've declared an array of IEnumerable instances, which contains a single element - the results of your getBeneficiarydetails method.

Assuming the getBeneficiarydetails method actually returns an IEnumerable<SomeType>, where SomeType is a class which contains properties called lastname and middlename, then something like this should work:

C#
IEnumerable<SomeType> requiredData = getBeneficiarydetails();
int index = 0;

foreach (SomeType item in requiredData)
{
    switch (index)
    {
        case 0:
        {
            txtlname.Text = item.lastname;
            txtmiddlename.Text = item.middlename;
            break;
        }
        case 1:
        {
            txtlnamesecond.Text = item.lastname;
            txtmiddlenamesecond.Text = item.middlename;
            break;
        }
        ...
    }
    
    index++;
}
 
Share this answer
 

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