【问题标题】:DevExpress gridView - trigger javascript alert from onRowInserted eventDevExpress gridView - 从 onRowInserted 事件触发 javascript 警报
【发布时间】:2011-12-12 02:10:13
【问题描述】:

我在 asp updatePanel 中有一个 DevExpress gridView。

 <asp:ScriptManager ID="ScriptManager1" runat="server" />
 <asp:UpdatePanel ID="upWWWGrid" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <div>
            <dx:ASPxGridView ID="grdWWW" runat="server" KeyFieldName="WWWID" AutoGenerateColumns="false" Visible="false" OnRowInserting="grdWWW_RowInserting" OnRowInserted="grdWWW_RowInserted">   
                 <Columns>
                    <dx:GridViewCommandColumn VisibleIndex="0" Caption=" ">
                        <ClearFilterButton Visible="True" />
                        <NewButton Visible="true" />
                        <EditButton Visible="true" />
                        <DeleteButton Visible="true" />
                    </dx:GridViewCommandColumn>
                    <dx:GridViewDataColumn FieldName="WWWID" VisibleIndex="1" Caption="WWW ID">
                        <EditFormSettings Visible="False" />
                    </dx:GridViewDataColumn>  
                    <SettingsEditing Mode="EditFormAndDisplayRow" EditFormColumnCount="2" />
                    <SettingsPager PageSize="20" AlwaysShowPager="true" />
                    <SettingsBehavior AllowSort="true" ConfirmDelete="true" />
                    <Settings ShowFilterRow="true" ShowTitlePanel="true" />
                </Columns>
            </dx:ASPxGridView>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

我想通过执行以下操作在 onRowInserted() 事件中触发 javascript 警报 以下:

string Message = "Hello World!"; 
ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", String.Format("alert('{0}');", Message), true);

但似乎从未注册过警报。我认为问题与 gridView 使用回调执行所有操作有关。知道创建新记录后如何触发此警报吗?我遇到的大多数示例都演示了如何使用客户端 SelectionChanged 事件和 onCustomCallback 来执行此操作。

【问题讨论】:

  • 行插入不是严格的服务器端吗?或者它是否足够接近在成功回调时触发一些事件?
  • 我能够在服务器端事件代码期间运行 ScriptManager.RegisterStartupScript(...),但由于 gridview 执行回调,因此永远不会触发 javascript。从技术上讲,我需要一个确认框,根据用户的响应,我需要执行另一个操作。

标签: c# javascript asp.net gridview devexpress


【解决方案1】:

你可以试试这样的:

protected void Grid_RowInsertedEvent(object sender, ASPxDataInsertedEventArgs e) 
{
    JSProperties["cp_RowInserted"] = true;
    ...
}

// I prefer this in grid's Init event handler but you can place it in 
// RowInserted as well
ClientSideEvents.EndCallback = 
    @"function(s,e)
    {
        if(s.cp_RowInserted!=null)
        {
            alert('row inserted');
            s.cp_RowInserted=null;
        }
    };";

【讨论】:

【解决方案2】:

您可能可以在行数据绑定事件上为网格注册 onclick 事件。这是您可以使用的代码片段

protected void Grid1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{         
}
else if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "alert('I am here')");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-23
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    相关资源
    最近更新 更多