嵌套的子DataList控件中的按钮单击事件问题!!!!!!!!!!!(急!!!!在线等待!!!!解决马上给分)
DataList1中的嵌套一个DataList2.通过DataList1的ItemDataBound事件中查找DataList2控件,给DataList2设置数据源,绑定数据.
在DataList2中的ItemDataBound事件中手动的绑定.现在有个问题是,我在DataList2中有个按钮.CommandName="Add",
private void DataList2_ItemCommand(object source, DataListCommandEventArgs e) 就是不能执行,为什么?
private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
{
DataRow dr=ds.Tables["Types"].Rows[e.Item.ItemIndex];
DataList DataList2 = (DataList)e.Item.FindControl("DataList2");
SqlParameter[] paras = new SqlParameter[]{
new SqlParameter("@TypeId",SqlDbType.Int)
};
paras[0].Value=dr["RecId"];
ds=conn.ExecuteProc("Products_SelectForTypeId",paras,"Products");
DataList2.DataSource=ds.Tables["Products"].DefaultView;
//绑定事件可以正常.
DataList2.ItemDataBound+=new DataListItemEventHandler(DataList2_ItemDataBound);
//DataList2.ItemCommand事件不能执行,为什么?如何解决?
DataList2.ItemCommand+=new DataListCommandEventHandler(DataList2_ItemCommand);
DataList2.DataBind();
ds.Tables.Remove("Products");
}
}
private void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
{
DataRow dr=ds.Tables["Products"].Rows[e.Item.ItemIndex];
Literal lbSmallImage=(Literal)e.Item.FindControl("lbSmallImage");
lbSmallImage.Text="<a href='ProductShow.aspx?RecId="+dr["RecId"].ToString()+"'><img src='../images/Products/"
+dr["BigImage_Save"].ToString()+"' border=0 height=75 width=75></a><br>";
Literal lbName=(Literal)e.Item.FindControl("lbName");
lbName.Text=dr["Name"].ToString();
Literal lbSCPrice=(Literal)e.Item.FindControl("lbSCPrice");
lbSCPrice.Text=dr["SCPrice"].ToString();
Literal lbSDPrice=(Literal)e.Item.FindControl("lbSDPrice");
lbSDPrice.Text=dr["SDPrice"].ToString();
Literal lbCJPrice=(Literal)e.Item.FindControl("lbCJPrice");
lbCJPrice.Text=dr["CJPrice"].ToString();
HyperLink hlXQ=(HyperLink)e.Item.FindControl("hlXQ");
hlXQ.NavigateUrl="ProductShow.aspx?RecId="+dr["RecId"].ToString();
HyperLink hlLB=(HyperLink)e.Item.FindControl("hlLB");
hlLB.NavigateUrl="ProductsListShow.aspx?TypeId="+dr["TypeId"].ToString();
}
}
private void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
{
Response.Write("aaaaaaaaaaaaaaaaaaaaa");
}