BulletedList问题!!
不知道出了什么问题,各位帮忙看看
<asp:BulletedList ID= "BulletedList1 " runat= "server " DisplayMode= "LinkButton " OnClick= "BulletedList1_Click ">
</asp:BulletedList>
======================================
public DataTable CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn( "id ", typeof(Int32)));
dt.Columns.Add(new DataColumn( "text ", typeof(string)));
for (int i = 0; i < 6; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "列表项目 " + i.ToString();
dt.Rows.Add(dr);
}
return dt;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = CreateDataSource();
this.BulletedList1.DataSource = dt;
this.BulletedList1.DataTextField = "id ";
this.BulletedList1.DataValueField = "text ";
this.BulletedList1.DataBind();
}
}
protected void BulletedList1_Click(object sender, BulletedListEventArgs e)
{
string str = this.BulletedList1.Items[e.Index].Value.ToString ();
Response.Write( " <script> alert( ' "+str + " ') </script> ");
}
似乎BulletedList1_Click没起作用
[解决办法]
你的代码没有问题啊.
Protected Sub BulletedList1_Click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.BulletedListEventArgs) Handles BulletedList1.Click
Response.Write(BulletedList1.Items(e.Index).Value)
End Sub
我可以正常执行.唯一不同的是,我在BulletedList1中是显示指定DataTextField,DataValueField这两个属性的.