点击大talist,没反应
点击大talist,没反应,而且在该方法开始设置断点,都不会停下,也没有任何反应。
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
int i = e.Item.ItemIndex;
string name;
switch (i)
{
case 0: name = "CLFJJK1"; break;
case 1: name = "GYFJJK1"; break;
case 2: name = "KBFJJK1"; break;
case 3: name = "HXFJJK1"; break;
case 4: name = "YXFJJK1"; break;
case 5: name = "YXFJJK2"; break;
case 6: name = "DXYFJJK1"; break;
default: name = ""; break;
}
if (e.CommandName == "machine")
{
Response.Redirect("MachineInfo.aspx?name=" + name);
}
}
结果发现,每次点击,都会首先触发page_load过程,所以才不会执行DataList1_ItemCommand。
解决方法:在Page_Load中加入 if (!IsPostBack),问题解决!