我有一些Asp.net dropdownList控件, 列表文档有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();
\
答案 0 :(得分: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
}
}
让我知道这有帮助
答案 1 :(得分: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);
}
}