如何将AsyncPostBackTrigger添加到DataGrid中的模板列,项模板,按钮

时间:2009-12-09 15:53:49

标签: asp.net datagrid templates triggers

我需要为DataGrid Template列中的两个按钮添加触发器。我发现有几个帖子说使用UniqueID将代码放在代码隐藏中。

我的逻辑(或者它可能不在正确的位置)是不对的。当我运行它时,我得到“对象引用没有设置为对象的实例”错误。

我在“gridSelectTrigger.ControlID = btnSessionSelect.UniqueID”语句中得到了这个。

这个逻辑是否需要在“ItemDataBound”事件中?或者我的逻辑错了?

<%@ Page Title="Admin Session Folders" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="AdminAddEditReleaseAndFiles.aspx.vb" Inherits="AdminAddEditReleaseAndFiles" Theme="Standard" %>

    
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

<asp:Panel ID="pnlEditTopic" runat="server" CssClass="modalPopupEditTopic" Style="display: none;" >
    <table cellspacing="0" class="borderTable0" width="100%" style="">
        <tr style="height:4px">
            <td colspan="6" align="center">
                <asp:ImageButton ID="btnAddTopic" runat="server" AlternateText="Add Topic" 
                    ImageUrl="~/App_Themes/Common/images/BtnApply.jpg" Height="28px">
                </asp:ImageButton>
                <asp:ImageButton ID="btnUpdateTopic" runat="server" AlternateText="Update Topic" 
                    ImageUrl="~/App_Themes/Common/images/BtnApply.jpg" Height="28px">
                </asp:ImageButton>
                <asp:ImageButton ID="btnDeleteTopic" runat="server" AlternateText="Delete Topic" 
                    ImageUrl="~/App_Themes/Common/images/BtnDelete.jpg" Height="28px">
                </asp:ImageButton>
                <asp:ImageButton ID="btnEditTopicClose" runat="server" AlternateText="Close Edit Topic Popup" 
                    ImageUrl="~/App_Themes/Common/images/BtnCancel.jpg" Height="28px">
                </asp:ImageButton>
            </td>
        </tr>  
    </table>
 </asp:Panel>

 </ContentTemplate>
 </asp:UpdatePanel>

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

 If Not (IsPostBack) Then
  Dim MainContent As ContentPlaceHolder = TryCast(Page.Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
  Dim UpdatePanelSessions As UpdatePanel = TryCast(MainContent.FindControl("UpdatePanelSessions"), UpdatePanel)
  Dim btnSessionSelect As Button = TryCast(UpdatePanelSessions.FindControl("btnSessionSelect"), Button)
  Dim btnSessionDetail As Button = TryCast(UpdatePanelSessions.FindControl("btnSessionDetail"), Button)
  Dim gridSelectTrigger As AsyncPostBackTrigger = New AsyncPostBackTrigger
  Dim gridDetailTrigger As AsyncPostBackTrigger = New AsyncPostBackTrigger
  gridSelectTrigger.ControlID = btnSessionSelect.UniqueID
  gridSelectTrigger.EventName = "Click"
  UpdatePanelSessions.Triggers.Add(gridSelectTrigger)
  gridDetailTrigger.ControlID = btnSessionDetail.UniqueID
  gridDetailTrigger.EventName = "Click"
  UpdatePanelSessions.Triggers.Add(gridDetailTrigger)
    End If

End Sub

谢谢你, 詹姆斯

1 个答案:

答案 0 :(得分:0)

知道了。更新面板需要将子项设置为true。