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"
C#
Last Comment
Camillia
8/22/2022 - Mon
burakiewicz
are you trying to bind a property to the text and a property to the value like this
List items = customerQ.Execute();
cbxCName.DataSource = items;
cbxCName.DataTextField="ItemName"
cbxCName.DataValueField="ItemId"
cbxCName.DataBind();
Camillia
ASKER
oh, let me see.
Camillia
ASKER
no, backto my orig question...how can I get the Items's first and second columns?
cbxCName.DataTextField="ItemName"
cbxCName.DataValueField="ItemId"
--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.
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();
}
List items = customerQ.Execute();
cbxCName.DataSource = items;
cbxCName.DataTextField="It
cbxCName.DataValueField="I
cbxCName.DataBind();