DevExpress gridView -触发javascript警报从onRowInserted事件
本文关键字:onRowInserted 事件 javascript gridView 触发 DevExpress | 更新日期: 2023-09-27 18:11:46
我有一个DevExpress gridView在一个asp updatePanel。
<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>
我想触发一个javascript警报在onRowInserted()事件通过执行:
string Message = "Hello World!";
ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", String.Format("alert('{0}');", Message), true);
但似乎警报从未被注册。我相信这个问题与gridView使用回调执行一切的事实有关。知道如何在创建新记录后触发此警报吗?我遇到的大多数例子都演示了如何使用客户端SelectionChanged事件和onCustomCallback来实现这一点。
您可以尝试这样做:
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;
}
};";
您可以在行数据绑定事件上为网格注册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')");