如何从ienumerable对象获取第3行或第2行值。 [英] how to get 3rd row or 2nd row values from ienumerable object.

查看:368
本文介绍了如何从ienumerable对象获取第3行或第2行值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

i确实要求以ienumerable< someclassname>的形式检索数据,因为我得到5行数据,我需要绑定第一行是某些asp.net文本框的值,第二行是某些其他文本框的值,第三行是某些其他文本框的值。

因为我已经编写了如下代码。



i以ienumerable< benefeciarydetails>的形式从businessclass库中获取所需的数据;类型。



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



所以,这里是为了将数据分配给所需的文本框,我写了如下。



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]。姓氏;

txtmiddlenamesecond.text = requireddata [i] .middlename;

}

if(i == 2){

txtlnamethird.text = requrieddata [i] .lastname;

txtmiddlenamethired.text = requireddata [i] .middlename;

}









}


这里
如果requireddata只包含一行,那么我需要将这些数据分配给第一个必需的文本框。而且所有空的都将被放置。我已经尝试了上面的代码,但没有得到正确的结果,PLZ帮助我解决这个问题,或者我应该更改我的代码。

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.

推荐答案

问题是你已经声明了一个 IEnumerable 实例的数组,其中包含一个元素 - getBeneficiarydetails 方法的结果。



假设 getBeneficiarydetails 方法实际返回 IEnumerable< SomeType> ,其中 SomeType 是一个类,其中包含名为 lastname middlename ,那么这样的事情应该有效:



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:

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++;
}


这篇关于如何从ienumerable对象获取第3行或第2行值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆