0

我有一些 Asp.net dropdownList 控件,List docs 有 3 个属性:DocID、UniqueIdentifier、Name。如何仅使用此跨越“IF”条件的记录填充 DDL。这是一个伪代码。

 List<IR_DocumentType> docs = IR_DocumentType.getDocType();
 foreach (IR_DocumentType item in docs)
 {
    if (item.DocID ==1)
    {
    }
 }
 //dropdownList
 DDL.DataSoure = docs;
 DDL.Bind();

\

4

2 回答 2

0

请参阅下面的代码

List<IR_DocumentType> docs = IR_DocumentType.getDocType();
 DDL.DataSoure = new DataTable(); // you can skip this 
 DDL.DataTextField = "Name";  //or "UniqueIdentifier"
 DDL.DataValueField = "DocID" ;
 DDL.Bind();
 foreach (IR_DocumentType item in docs)
  {
 if (item.DocID ==1)
    {
     DDL.Items.Insert(item.DocID, item.Naem );
     //or item.UniqueIdentifier you can also use     
    //a counter instead of item.DocID
                }
            }

让我知道这有帮助

于 2013-08-31T07:49:19.947 回答
0
        List<IR_DocumentType> docs = IR_DocumentType.getDocType();

        foreach (IR_DocumentType item in docs)
        {
            if (item.DocID ==1) // your condition
            {
              DDL.Items.Add(new ListItem(item.Name, item.UniqueIdentifier);
            }
        }
于 2013-08-31T09:01:02.497 回答