日期:2014-05-18  浏览次数:20493 次

关于gridview中的模板列
protected void ImageButton1_Command(object sender, CommandEventArgs e)
  {
  int typeid = 0;
  typeid = Convert.ToInt32(e.CommandArgument);
  Response.Write("<script>OpenSubWindow('UpdateDisasterType.aspx?id=" + typeid + "','300','300');</script>");
   
  }
ImageButton1是gridview中模板列中添加的一个imagebutton,我想要实现的是点击imagebutton时出现一个弹不框,为什么我点了出现的是所选的那行成了编辑状态呢,请高手赐教!

------解决方案--------------------
private void GridView1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{

ImageButton imgDel=(ImageButton)e.Item.FindControl("ImageButton1");
int typeid = 0; 
typeid = Convert.ToInt32(e.CommandArgument); 
// Response.Write(" <script>OpenSubWindow('UpdateDisasterType.aspx?id=" + typeid + "','300','300'); </script>"); 
imgDel.Attributes.Add("onclick","OpenSubWindow('UpdateDisasterType.aspx?id=" + typeid + "','300','300');");
}
}
------解决方案--------------------
private void dg_ddl_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
ImageButton delete = (ImageButton)e.Item.FindControl("按钮的id");
delete.Attributes.Add("onclick", "你要调用的方法");
}
}
------解决方案--------------------
gridview里没有ItemDataBound事件,但有 RowDataBound事件