나는이 같은 새로운 동적 ItemTemplate을 구현 잡은하지 :이벤트는
는private sealed class CustomItemTemplate : ITemplate
{
public CustomItemTemplate()
{}
void ITemplate.InstantiateIn(Control container)
{
Table ItemTable = new Table();
ItemTable.CssClass = "tablewidth";
TableRow btnRow = new TableRow();
ItemTable.Rows.Add(btnRow);
TableCell btnCell = new TableCell();
btnCell.CssClass = "bgcolorBlueLight";
btnCell.ColumnSpan = 2;
btnRow.Cells.Add(btnCell);
ImageButton ImgBtnfvPrincipalInsertMode = new ImageButton();
ImgBtnfvPrincipalInsertMode.CausesValidation = false;
ImgBtnfvPrincipalInsertMode.ImageUrl = "~/Images/icon_insert_16.gif";
ImgBtnfvPrincipalInsertMode.CommandName = "New";
ImageButton ImgBtnfvPrincipalUpdateMode = new ImageButton();
ImgBtnfvPrincipalUpdateMode.CausesValidation = false;
ImgBtnfvPrincipalUpdateMode.ImageUrl = "~/Images/icon_edit_16.gif";
ImgBtnfvPrincipalUpdateMode.CommandName = "Edit";
btnCell.Controls.Add(ImgBtnfvPrincipalInsertMode);
btnCell.Controls.Add(ImgBtnfvPrincipalUpdateMode);
container.Controls.Add(ItemTable);
}
}
그것은 두 개의 버튼, 삽입 모드를 여는 첫 번째 및 업데이트 모드를 열고 두 번째가 포함되어 있습니다. 그들은 문제없이 나타난다.
내 목표는 formview에서 사용하는 것입니다
protected void Page_Load(object sender, EventArgs e)
{
formView1.ItemTemplate = new CustomItemTemplate();
}
그리고 두 버튼에서 명령을 잡으려고 싶습니다
protected void formView1_ItemCommand(object sender, FormViewCommandEventArgs e)
{
System.Diagnostics.Debug.WriteLine("ITEM COMMANDNAME : " + e.CommandName);
}
불행하게도, formView1_ItemCommand 아무것도 할 때 표시되지 않습니다 내 버튼을 클릭하십시오
그래도 ItemTemplate을 클래식으로 선언하면 다음과 같이됩니다.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ProspectsCustomFormView.ascx.cs" Inherits="controls_ProspectsCustomFormView" %>
<asp:FormView ID="formView1" runat="server" OnItemCommand="formView1_ItemCommand">
<ItemTemplate>
<asp:Table ID="ItemTable" runat="server" CssClass="tablewidth">
<asp:TableRow>
<asp:TableCell CssClass="bgcolorBlueLight" ColumnSpan="2">
<asp:ImageButton ID="ImgBtnfvPrincipalInsertMode" runat="server" CommandName="New" CausesValidation="False" ImageUrl="~/Images/icon_insert_16.gif" ToolTip="New"/>
<asp:ImageButton ID="ImgBtnfvPrincipalUpdateMode" runat="server" CommandName="Edit" CausesValidation="False" ImageUrl="~/Images/icon_edit_16.gif" ToolTip="Edit" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ItemTemplate>
</asp:FormView>
그러면 작동합니다 ...
어떤 솔루션을 제안합니까?
편집
는 formView 실제로 사용자 컨트롤 내부에 싸여 얘기를 깜빡 했네요 : 이것은 내 경험 밖에 조금
public partial class controls_CustomFormView : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
fv.ItemTemplate = new CustomItemTemplate();
}
private sealed class CustomItemTemplate : ITemplate
{...}
}
여기에서 작동합니다. ItemCommand가 바인딩되어 있습니까? 이벤트는 기본적으로 버블 링되어야합니다 ... – Luizgrs
Luizgrs : "ItemCommand가 바인드 됨"은 무엇을 의미합니까? – codablank1
당신은 당신의 aspx 에이 같은 것을 볼 수 있습니까? 예 : onitemcommand = "formView1_ItemCommand"예. classicaly를 선언 할 때 트리거되지 않습니다. –
Luizgrs