Camillia
asked on
Looping thru a List to find the first and second items
I have a list like this:
List<CustomerQ.Customer> items = customerQ.Execute();
cbxCName.DataSource = items;
cbxCName.DataBind();
I want to loop thru that List and assign the first and second items to the first and second item of that checkbox cbxCName:
cbxCName.Items[0].Text = "first item column of Items"
cbxCName.Items[0].Value = "second item column of Items"
List<CustomerQ.Customer> items = customerQ.Execute();
cbxCName.DataSource = items;
cbxCName.DataBind();
I want to loop thru that List and assign the first and second items to the first and second item of that checkbox cbxCName:
cbxCName.Items[0].Text = "first item column of Items"
cbxCName.Items[0].Value = "second item column of Items"
ASKER
oh, let me see.
ASKER
no, backto my orig question...how can I get the Items's first and second columns?
cbxCName.DataTextField="It emName"
cbxCName.DataValueField="I temId"
--what is IteName?what is ItemId?
*** Orig code has an itemdatabound like below. I want to replace that item databound code and do it the binding all in one. I want to remove the ItemDataBound.
e.Item.Text = ((CustomerQ.Customer)e.Ite m.DataItem ).LastName .ToString( );
e.Item.Value = ((CustomerQ.Customer)e.Ite m.DataItem ).Id.ToStr ing();
cbxCName.DataTextField="It
cbxCName.DataValueField="I
--what is IteName?what is ItemId?
*** Orig code has an itemdatabound like below. I want to replace that item databound code and do it the binding all in one. I want to remove the ItemDataBound.
e.Item.Text = ((CustomerQ.Customer)e.Ite
e.Item.Value = ((CustomerQ.Customer)e.Ite
ASKER
I can do :
items[0].id and items[0].lastname
but can I do this in one line or do i need to loop?
items[0].id and items[0].lastname
but can I do this in one line or do i need to loop?
ASKER
I tried this but I dont see anything in my combo box:
List items = customerQuery.Execute();
cbxCName.DataSource = items;
cbxCName.DataTextField = items[0].LastName.ToString ();
cbxCName.DataValueField = items[0].Id.ToString();
cbxCName.DataBind();
List items = customerQuery.Execute();
cbxCName.DataSource = items;
cbxCName.DataTextField = items[0].LastName.ToString
cbxCName.DataValueField = items[0].Id.ToString();
cbxCName.DataBind();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
let me try that but this also worked:
int i;
for (i = 0; i< items.Count - 1; i++)
{
cbxCName.Items[i].Text = items[i].LastName.ToString ();
cbxCName.Items[i].Value = items[i].Id.ToString();
}
int i;
for (i = 0; i< items.Count - 1; i++)
{
cbxCName.Items[i].Text = items[i].LastName.ToString
cbxCName.Items[i].Value = items[i].Id.ToString();
}
ASKER
yes, your method is much better.Thanks
List items = customerQ.Execute();
cbxCName.DataSource = items;
cbxCName.DataTextField="It
cbxCName.DataValueField="I
cbxCName.DataBind();