web DropDownList绑定数据源的几种方式
第一种
this.ddltype.DataTextField = "btName";//显示的值
this.ddltype.DataValueField = "btId";//获取dropdownlist中的值
ddltype.DataSource = service.GetBusinessTypeAll("");
this.ddltype.DataBind();
第二种
DataTable dt_GetBusinessName = service.GetBusinessTypeAll("");
//表中无数据的话直接返回
if (dt_GetBusinessName == null)
return;
for (int i = 0; i < dt_GetBusinessName.Rows.Count; i++)
{
ddltype.Items.Add(new ListItem(dt_GetBusinessName.Rows[i]["btName"].Trim();//显示的值
dt_GetBusinessName.Rows[i]["btId"].ToString().Trim()));
}
ddltype.Items.Add(new ListItem("全部", "-1"));
ddltype.Text = "全部";
windows combox的手写数据绑定
第一种:
cCombox1.DisplayMember = "btName";//显示的值
cCombox1.ValueMember = "btId";
cCombox1.DataSource = _manageService.GetBusinessTypeAll(this.UserInfo.uNote1);
第二种:
DataTable dt_GetStateByName = _financeService.GetStateByNam(UserInfo.uNote1);
//表中无数据的话直接返回
if (dt_GetStateByName == null)
return;
for (int i = 0; i < dt_GetStateByName.Rows.Count; i++)
{
cbType2.Items.Add(new ListItem(dt_GetStateByName.Rows[i]["osState"].Trim(),
dt_GetStateByName.Rows[i]["osName"].ToString().Trim()));//显示的值
}
cbType2.Items.Add(new ListItem("-1", "全部"));
cbType2.Text = "全部";
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛