我在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使用Callbacks执行所有操作有关。知道如何在创建新记录后触发此警报吗?我遇到的大多数示例演示了如何使用客户端SelectionChanged事件和onCustomCallback来执行此操作。
答案 0 :(得分:3)
您可以尝试这样的事情:
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;
}
};";
答案 1 :(得分:0)
您可以在行数据绑定事件上注册网格的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')");