我正在尝试编写一个更通用的方法来填充 ASP.NET 下拉列表或带有状态的 Telerik RadComboBox。我想将控件作为参数传递给方法。我有一个包含所有状态的 DataTable,我循环遍历它(见下文) - 我想让它适用于 Telerik RadComboBox - 所以我需要更改第一个参数,以及我插入新的部分ListItem - 对于 Telerik RadComboBox,它是新的 RadComboBoxItem。我怎样才能做到这一点?
public void PopulateStates(DropDownList ddlStates, string country)
{
ddlStates.Items.Clear();
DataLookup dl = new DataLookup();
DataTable dt = dl.GetStatesByCountry(country);
if (dt != null)
{
if (dt.Rows.Count > 0)
{
ddlStates.Items.Insert(0, new ListItem(""));
for (int i = 0; i < dt.Rows.Count; i++)
{
ddlStates.Items.Add(new ListItem(dt.Rows[i]["STCD_Descr"].ToString(),
dt.Rows[i]["STCD_State_CD"].ToString()));
}
}
}
}