/// <summary>
/// 绑定DataTable数据源
/// </summary>
/// <param name="list"></param>
/// <param name="textField"></param>
/// <param name="valueField"></param>
/// <param name="dt"></param>
public void bindDataListBox(ListBox list, string textField, string valueField, DataTable dt)
{
list.DataSource = dt;
list.DataTextField = textField;
list.DataValueField = valueField;
list.DataBind();
}
/// <summary>
/// 绑定一个数据项
/// </summary>
/// <param name="list"></param>
/// <param name="textString"></param>
/// <param name="valueString"></param>
public void bindItemListBox(ListBox list, string textString, string valueString)
{
ListItem item = new ListItem();
item.Text = textString;
item.Value = valueString;
list.Items.Add(item);
}
谢谢
listbox.add(ds.table[0].tostring());
谢谢
写个例子for you
ArrayList list = new ArrayList(); list.Add("红"); list.Add("橙"); list.Add("黄"); list.Add("绿"); list.Add("青"); list.Add("蓝"); list.Add("紫"); listBox1.DataSource = list;
谢谢!
利用DataSource 属性进行绑定
谢谢!