当我们在对DropDownList绑定数据的时候
DropDownList1.DataTextField = "";DataTextField 绑定要显示的值
DropDownList1.DataValueField = "";DataValueField 绑定value值
可是当绑定的时候没有value值的话,value的值就会和Text值相等,可是我们value值又不想取文字形式的
这时可以用DropDownList的DataBound事件


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] BookingStatus = { "NoUse", "未提交", "已提交", "已取消", "受理中", "已退回", "已订妥", "已过期" };
DropDownList1.DataSource = BookingStatus;
DropDownList1.DataBound += new EventHandler(DropDownList1_DataBound);
DropDownList1.DataBind();
}
}
void DropDownList1_DataBound(object sender, EventArgs e)
{
int i = 0;
//ListControl此类由其他类(如 CheckBoxList、DropDownList、ListBox 和 RadioButtonList 类)继承以提供通用的基本功能
ListControl list = sender as ListControl;
foreach (ListItem l in list.Items)
{
l.Value = i.ToString();
i++;
}
}
{
if (!IsPostBack)
{
string[] BookingStatus = { "NoUse", "未提交", "已提交", "已取消", "受理中", "已退回", "已订妥", "已过期" };
DropDownList1.DataSource = BookingStatus;
DropDownList1.DataBound += new EventHandler(DropDownList1_DataBound);
DropDownList1.DataBind();
}
}
void DropDownList1_DataBound(object sender, EventArgs e)
{
int i = 0;
//ListControl此类由其他类(如 CheckBoxList、DropDownList、ListBox 和 RadioButtonList 类)继承以提供通用的基本功能
ListControl list = sender as ListControl;
foreach (ListItem l in list.Items)
{
l.Value = i.ToString();
i++;
}
}