テスト中の VB.Net アプリケーションを継承しましたが、ItemCommand イベントが発生しません... これは VB.Net 4.0 アプリケーションです。
このエラーについて Web を検索し、アプリケーションのコードをダブルチェックしました。
このイベントは、page_load イベントの後のポストバックで発生するはずです。ただし、ImageButton をクリックすると (ポストバックを強制し、できれば ItemCommand イベントを実行するため)、Page.IsPostBack プロパティはまだ FALSE に設定されているため、ItemCommand イベントを実行できません。このプロパティがまだ FALSE に設定されている理由がわかりません。明らかに、ポストバックが発生していることをページに知らせる方法が必要です。runat="server" タグがあるため、ImageButton でこれを処理する必要があります。
以下はコードスニペットです。Item コマンドを起動するために何をする必要があるか教えてもらえますか? 上で言ったことは真実だと思います。ページが読み込まれた後、プロパティがまだ FALSE に設定されている ImageButton を押す理由がわかりません。
HTML
<asp:DataList ID="lstReferrals" runat="server" DataKeyField="ReferringAffiliateID"
OnItemCommand="lstReferrals_ItemCommand" CellPadding="4" Summary="Referral Design Table"
Width="800"><ItemTemplate>
<tr class="small" bgcolor="#FFFFFF">
<td>
<asp:ImageButton ID="btnSelect" AlternateText="Select" ImageUrl='<%# NodeImage(1) %>'
CommandName="select" runat="server" />CODE BEHINDPrivate Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not (Request.Params("ItemIndex") Is Nothing) Then
itemIndex = Int32.Parse(Request.Params("ItemIndex"))
Else
itemIndex = Convert.ToInt32(Null.SetNull(itemIndex))
End If
If Not Page.IsPostBack Then
LoadReferrals()
If Not Null.IsNull(itemIndex) Then
lstReferrals.SelectedIndex = itemIndex
LoadReferrals()
End If
End If
End Sub
Protected Sub lstReferrals_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles lstReferrals.ItemCommand
Try
errormessage.Visible = False
' Determine the command of the button (either "select" or "collapse")
Dim command As String = CType(e.CommandSource, ImageButton).CommandName
' Update asp:datalist selection index depending upon the type of command
' and then rebind the asp:datalist with content
Select Case command
Case "collapse"
lstReferrals.SelectedIndex = -1
LoadReferrals()
Case "select"
lstReferrals.SelectedIndex = e.Item.ItemIndex
LoadReferrals()