huangtu

//加载显示数据

protected void Page_Load(object sender, EventArgs e) 

{
if (!IsPostBack)
{
BindListBox();   
}
}

/// 绑定类别名称到ListBox
void BindListBox()
{
string sql = "SELECT * FROM ClassTable WHERE PlateID=2 OR PlateID=4";
DataTable myClassTable = new ClassTable_bll().WhereToClassTable(sql);
ListBox1.DataTextField = "MerchClassName";
ListBox1.DataValueField = "ClassID";
ListBox1.DataSource = myClassTable.DefaultView;
ListBox1.DataBind();
}

///单击butto按钮 取选中项的具体数据

protected void Button1_Click(object sender, EventArgs e)
{
string str = "";
for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected == true)
{
str = str + ListBox1.Items[i].Text+",";
}
}
this.Response.Write("alert(\'" + str + "\');");
}

分类:

技术点:

相关文章: