//当DropDownList中有这个值时,默认选中,否则选中第一个
private void setDropDownListValue(DropDownList drp, string value) { if (drp.Items.FindByValue(value) == null) { drp.SelectedIndex = 0; } else { drp.SelectedValue = value; } } //根据text确定下拉框中的选中项
private void setDropDownListText(DropDownList drp, string text) { if (drp.Items.FindByText(text) == null) { drp.SelectedIndex = 0; } else { for (int i = 0; i < drp.Items.Count; i++) { if (drp.Items[i].Text == text) { drp.SelectedIndex = i; break; } } } } |
|