通过单击警告框的“确定”按钮在警报框中显示数据 [英] displaying data in alert box by clicking ok button of alert box

查看:78
本文介绍了通过单击警告框的“确定”按钮在警报框中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在警告框中显示名称,然后在网格视图的格式中单击警告框的确定按钮,并在gridview中更新或删除属性,在另一个警告框中显示该名称及其ID。任何机构都有解决方案所以请提供

解决方案

Hello Masroor,



如果我正确理解你的问题那么请参考 [ ^ ]文章。它显示了如何使用gridview进行INSERT / UPDATE。



现在我们假设您要通过首先显示名称来确认删除操作,然后再显示另一个显示名称和ID的确认。在这种情况下,您可以连接以下JavaScript函数。

  function  confirmDelete(strName,strId){
var r = confirm( 将删除 + strName);
if (r == true ){
r = confirm( 将删除id为 + strId + 的记录并命名为 + strName);
if (r == true return true ;
}
返回 false ;
}



javascript连接将在gridview的 RowDataBound 事件中完成。因此,请从上面文章中显示的aspx文件中删除onClientClick代码。代码中的连接代码将如下所示:

  protected   void  GridView1_OnRowDataBound( object  sender,GridViewRowEventArgs e){
try {
if (e.Row.RowType == DataControlRowType.DataRow){
DataRowView drEachRow =(DataRowView)e.Row 。数据项;
LinkBut​​ton lbBind =(LinkBut​​ton)e.Row.FindControl( lnkRemove);
lbBind.Attributes.Add( onclick javascript:return confirmDelete(' + DataBinder.Eval(e.row.DataItem, ContactName)+
',' + DataBinder.Eval(e.row.DataItem, CustomerID)+ '););
}
}
catch (例外objExp){
// 处理异常
}
}



问候,


I want to display name in alert box and then display that name with its id in another alert box by clicking ok button of alert box in the format of grid view with having property to update or delete within gridview. Any body have a solution so please provide

解决方案

Hello Masroor,

If I understand your question correctly then please refer to this[^] article. It shows how to do INSERT/UPDATE using a gridview.

Now lets assume that you want to confirm the delete operation by first displaying the name, followed by another confirm showing the name and the id. In that case you can hook up following JavaScript function.

function confirmDelete(strName, strId) {
    var r = confirm("Will delete " + strName);
    if (r == true) {
        r = confirm("Will delete record having id " + strId + " and name " + strName);
        if (r == true) return true;
    }
    return false;	
}


The javascript wiring will be done in RowDataBound event of the gridview. So do remove the onClientClick code from the aspx file shown in above article. The wiring up code in your code behind will be something like one shown below.

protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e ) {
    try {
        if (e.Row.RowType == DataControlRowType.DataRow) {
            DataRowView drEachRow = (DataRowView) e.Row.DataItem;
            LinkButton lbBind= (LinkButton )e.Row.FindControl("lnkRemove");
            lbBind.Attributes.Add("onclick", "javascript:return confirmDelete('" + DataBinder.Eval(e.row.DataItem, "ContactName") +
                                        "', '" + DataBinder.Eval(e.row.DataItem, "CustomerID") + "');");
        }
    }
    catch(Exception objExp) {
        // handle exception
    }
}


Regards,


这篇关于通过单击警告框的“确定”按钮在警报框中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆