[英]Datagrid EditItemTemplate button event not firing
我在Gridview中動態創建Item模板。
TemplateColumn BtnTmpField = new TemplateColumn();
BtnTmpField.ItemTemplate = new DynamicallyTemplatedGridViewHandler(ListItemType.Item, "Edit", "Button");
BtnTmpField.HeaderTemplate = new DynamicallyTemplatedGridViewHandler(ListItemType.Header, "Edit", "Command");
BtnTmpField.EditItemTemplate = new DynamicallyTemplatedGridViewHandler(ListItemType.EditItem, "Update", "Button"); dgdefault.Columns.Add(BtnTmpField);
public void InstantiateIn(System.Web.UI.Control Container)
{
switch (ItemType)
{
case ListItemType.Header: Literal header_ltrl = new Literal();
header_ltrl.Text = "" + FieldName + "";
Container.Controls.Add(header_ltrl);
break;
case ListItemType.Item:
switch (InfoType)
{
case "Button":
LinkButton edit_button = new LinkButton();
edit_button.ID = "edit_button";
edit_button.Text = "Edit";
edit_button.CommandName = "Edit";
Container.Controls.Add(edit_button);
break;
}
break;
case ListItemType.EditItem:
if (InfoType == "Button")
{
LinkButton update_button = new LinkButton();
update_button.ID = "update_button";
update_button.CommandName = "Update";
update_button.Text = "Update ";
LinkButton cancel_button = new LinkButton();
cancel_button.ID = "cancel_button";
cancel_button.CommandName = "Cancel";
cancel_button.Text = "Cancel";
Container.Controls.Add(update_button);
Container.Controls.Add(cancel_button);
}
break;
}
}
當我選擇“編輯”按鈕時,“更新”和“取消”按鈕將顯示,並且所選行可編輯。 單擊“編輯”時,將正確觸發DataGrid的ItemCommand事件。 當我單擊“更新”或“取消”按鈕時,沒有任何反應。 當我將onUpdateCommand或onCancelCommand顯式放置在ascx頁面中時,ItemCommand不會觸發,UpdateCommand或CancelCommand也不會觸發。 我不知道為什么在單擊EditItemTemplate中的按鈕時什么都沒有觸發。 同樣,所有內容都在每個page_init回發中加載。 任何提示都會有所幫助
我想到了。 我基本上創建了一個項目模板,並在不使用edititem的情況下添加了3個單獨的按鈕。 在數據網格itemdatabound函數中,我只是隱藏並顯示需要顯示的按鈕。
您是否正在重新綁定網格的PreRender中的事件?
我今天有同樣的問題。 我注意到它正在調用編輯項目的“頁眉”模板。 不知道為什么,但是在“ switch”之前添加以下內容:
System.Diagnostics.Debug.WriteLine(string.Format("Template: {0}",ItemType.ToString()));
如果要測試的記錄數量很少,則在嘗試編輯記錄時應該可以看到它調用了“標頭”項類型。
我很想知道您是否遇到同樣的事情。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.