列表视图OnItemCommand这么想的火起来

当我按下在列表视图或者LinkBut​​ton的忽略了最低在所有列表视图OnItemCommand这么想的火起来

<div> 

<%

String[] d1 = { "1", "2", "3" };

String[] d2 = { "4", "5", "6", "7" };

ListView1.DataSource = d1;

ListView1.DataBind();

ListView2.DataSource = d2;

ListView2.DataBind();

%>

<asp:ListView ID="ListView1" runat="server" OnItemCommand="lv_command">

<LayoutTemplate>

<ul>

<asp:PlaceHolder ID="itemPlaceholder" runat="server" />

</ul>

</LayoutTemplate>

<ItemTemplate>

<asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>

</ItemTemplate>

</asp:ListView>

<asp:ListView ID="ListView2" runat="server" OnItemCommand="lv_command">

<LayoutTemplate>

<ul>

<asp:PlaceHolder ID="itemPlaceholder" runat="server" />

</ul>

</LayoutTemplate>

<ItemTemplate>

<asp:LinkButton ID="LinkButton2" runat="server">LinkButton</asp:LinkButton>

</ItemTemplate>

</asp:ListView>

</div>

protected void lv_command(object sender, ListViewCommandEventArgs e)

{

int i = 0;

}

回答:

设置每个了LinkBut​​ton的CommandName属性,例如t被提出,你可以检测它是否是从一个链接按钮如下触发:

 protected void lv_command(object sender, ListViewCommandEventArgs e) 

{

if(e.CommandName == "MyCommand")

{

//do something

}

}

而且是更多的性能,明智的结合上只有初始加载列表视图,并在需要的时候再从某些事件处理程序绑定它:

protected void Page_Load(object sender, EventArgs e) 

{

if(!Page.IsPostBack)

{

String[] d1 = { "1", "2", "3" };

String[] d2 = { "4", "5", "6", "7" };

ListView1.DataSource = d1;

ListView1.DataBind();

ListView2.DataSource = d2;

ListView2.DataBind();

}

}

回答:

移动火起来进行数据绑定到代码隐藏的逻辑:

protected void Page_Load(object sender, EventArgs e) 

{

String[] d1 = { "1", "2", "3" };

String[] d2 = { "4", "5", "6", "7" };

ListView1.DataSource = d1;

ListView1.DataBind();

ListView2.DataSource = d2;

ListView2.DataBind();

}

protected void lv_command(object sender, ListViewCommandEventArgs e)

{

int i = 0;

}

当ItemCommand甚至

<asp:LinkButton ID="LinkButton1" runat="server" CommandName="MyCommand">LinkButton</asp:LinkButton> 

这样:

以上是 列表视图OnItemCommand这么想的火起来 的全部内容, 来源链接: utcz.com/qa/267024.html

回到顶部