?????????ListBox???
???????????? ???????[ 2015/2/28 13:27:25 ] ????????????? button
????1. The HTML Markup
<div>
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox> <br />
<asp:Button ID="Button1" runat="server" Text="Get Selected Values" OnClick="Button1_Click" />
</div>
????2. The button event
protected void Page_Load(object sender?? EventArgs e)
{
if (!IsPostBack)
{
//???????
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn() { ColumnName = "Id"?? DataType = typeof(int) });
dt.Columns.Add(new DataColumn() { ColumnName = "Name"?? DataType = typeof(string) });
dt.Rows.Add(1?? "Scott");
dt.Rows.Add(2?? "John");
dt.Rows.Add(3?? "Tom");
dt.Rows.Add(4?? "Ross");
ListBox1.DataValueField = "Id";
ListBox1.DataTextField = "Name";
ListBox1.DataSource = dt;
ListBox1.DataBind();
}
}
protected void Button1_Click(object sender?? EventArgs e)
{
int id = int.Parse(ListBox1.SelectedItem.Value);
Response.Write(id);
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11