我試圖從GridView的頁腳點擊一個ImageButton事件點擊,但我沒有開火, 我會感謝任何幫助, 在此先感謝, 這裏是代碼添加單擊圖像buttonbutton裏面gridview動態
protected void grvBubDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
ImageButton imgbtnSendMail = new ImageButton();
//ImageButton imgEdit = new ImageButton();
imgbtnSendMail.ImageUrl = "~/Images/mail01.png";
imgbtnSendMail.AlternateText = "Edit";
imgbtnSendMail.ToolTip = "for send mail press here";
imgbtnSendMail.Width = imgbtnSendMail.Height = 20;
//imgbtnSendMail.CommandName = "sendMail";
//imgbtnSendMail.CommandArgument = "somevalue";
imgbtnSendMail.Click += new ImageClickEventHandler(imgbtnSendMail_Click);
//imgbtnSendMail.Attributes["runat"] = "server";
//imgbtnSendMail.Attributes["onclick"] = "imgbtnSendMail_Click";
e.Row.Cells[6].Controls.Add(imgbtnSendMail);
}
}
protected void imgbtnSendMail_Click(object sender, ImageClickEventArgs e)
{
string Text = "Image clicked";
}
我也試過,但它不進去grvBubDetails_RowCommand!這是因爲它是一個頁腳? – 2013-04-11 09:54:51
我做了類似的代碼之前用Button,但用ImageButton我不知道爲什麼它不起作用 – 2013-04-11 09:57:35
EnableViewState是否爲頁面和網格視圖控件?如果在頁面加載事件中有數據代碼,請確保它位於if(!IsPostBack)塊中。 – 2013-04-11 10:06:24