私がテストしているItem.Commandイベントが発生していないVB.Netアプリケーションを継承しました。これはVB.Net 4.0アプリケーションです。ItemCommandイベントがDataListに対して起動しない
私はこのエラーをWebで検索し、アプリケーションでコードをチェックしました。
このイベントは、page_loadイベントの後にポストバックで発生するはずです。しかし、ImageButtonをクリックして(ポストバックを強制し、ItemCommandイベントをうまく実行する)、Page.IsPostBackプロパティはFALSEに設定されているため、ItemCommandイベントを実行できません。なぜこのプロパティがFALSEに設定されるのかわかりません。明らかに、ポストバックが発生していることをページに示す方法が必要です。 runat = "server"タグがあるので、ImageButtonはこれを処理する必要があります。
以下はコードスニペットです。 Itemコマンドを起動するために何をする必要があるか教えてもらえますか?私が上で言ったことは真実だと私は信じている。私はページがロードされた後、なぜプロパティがFALSEに設定されるのかImageButtonを押した理由を知らない。私は火にOnItemCommandイベントを設定しますPage_Loadメソッドでイベントハンドラを追加するために必要な
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()