今日は私が別の問題を抱えていて、二度目に助けに来てくれて特別な運が必要です。そして、私は本当にこれに助けが必要です。ListViewの動的イベントハンドラ?
私はボタンコントロールを持っているlistViewコントロールを持っています。私はこのボタンにイベントハンドラを追加しようとしていますが、私はここに来る前にたくさんのことを知っていましたが、私にはわかりにくい例があります。
私が必要とするのは、イベントハンドラをボタンに追加することです。ボタンを押すと、サーバ側でいくつかの関数(イベントハンドラ)が実行されます。
List of all the books that are currently in the Library.
<table width="630" cellpadding="2" cellspacing="5"/>
<tr style="background-color:#DBE2E2;">
<th>Image</th>
<th>Book</th>
<th>Description</th>
</tr>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</table>
<p>
<asp:DataPager ID="pageTopics" runat="server" PageSize="5">
<Fields>
<asp:NextPreviousPagerField ShowFirstPageButton="false" ShowPreviousPageButton="true" ShowNextPageButton="false" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ShowFirstPageButton="false" ShowPreviousPageButton="false" ShowNextPageButton="true" ShowLastPageButton="false" />
</Fields>
</asp:DataPager>
</p>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td valign="top"> <br />
<asp:Image ID="book_img" ImageUrl='<%# Eval("book_img") %>' Height="100" Width="100" runat="server" />
</td>
<td valign="top"><p><b>Book Name: </b><asp:Label ID="book_name" runat="server" Text='<%# Eval("book_name") %>' /><br />
<b>Author: </b><asp:Label ID="book_author" runat="server" Text='<%# Eval("book_author") %>' /><br />
<p></td>
<td valign="top"><p><asp:Label ID="book_short_desc" runat="server" Text='<%# Eval("book_short_desc") %>' /><br />
<b>Sku id: </b><asp:Label ID="book_squ" runat="server" Text='<%# Eval("book_squ") %>' /><br />
<b>Arrived On: </b><asp:Label ID="book_arrived" runat="server" Text='<%# Eval("book_arrived") %>' />
<asp:HyperLink ID="bookDesc" runat="server" NavigateUrl='<%# "BookDesc.aspx?id=" + Eval("book_id") %>' Text="To read more..." />
<asp:Button ID="orderbook" runat="server" CommandName="order" CommandArgument="ordernow" Text="order now" />
</p></td>
</tr>
</ItemTemplate>
そして、分離コードで、私は次のコードを実行してみてください:ここで
は私が次に EnableEventValidation="false"
ListViewコントロール自体持っている上にはASPX のコードです:
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
book_list.ItemCommand += new EventHandler<ListViewCommandEventArgs>(book_list_ItemCommand);
}
void book_list_ItemCommand(object sender, ListViewCommandEventArgs e)
{
testLabel.Text = e.CommandArgument.ToString();
//throw new NotImplementedException();
}
しかし、私はbook_list_ItemCommandをデバッグするときは実行されません。
私は本当にこの1つの助けが必要です。
ありがとうございます。