protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton db = (LinkButton)e.Row.Cells[3].Controls[0];
            // Get information about the product bound to the row            Northwind.ProductsRow product = (Northwind.ProductsRow)((System.Data.DataRowView)e.Row.DataItem).Row;            db.OnClientClick = string.Format("return confirm('Are you certain you want to delete the {0} product?');", product.ProductName.Replace("'", @"\'"));
        }
    }
这是一个在Gridview中给删除按钮增加提示的做法,最后一句我觉得有点复杂,不理解.能详细讲一下这句的运作流程吗?

解决方案 »

  1.   

    <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="删除" OnClientClick="return confirm('确定要删除这条记录吗?');">
                </asp:LinkButton>如果是在模板中这样设置其属性,我想象上面一样可以有提示删除的字段的信息,怎么写?
      

  2.   

    就是增加个客户端点击事件,当客户端点击后,会执行JS脚本,内容就是:
    string.Format("return confirm('Are you certain you want to delete the {0} product?');", product.ProductName.Replace("'", @"\'"))
      

  3.   

    @这个有什么用? string replace的方法不是只把(old,new)把老的转换成新的吗?那ProductName的值又是如何跑到{0}  实现的功能我明白,但是里面的机制不理解.
      

  4.   

     string.Format()方法就是可以吧productname放到{0}里,
    如下面这个可以把你好,放到{0}里,把再见放到{1}里,当然你也可以增加多个参数,具体参看string.Format()方法
    string.Format("{0}:{1}","你好,再见");
      

  5.   

    @的作用就是不让编译器将“\'”中的“\”识别为一个转义符而是识别为 \ 符号
    product.ProductName.Replace("'", @"\'")
    这句代码的意思就是将 字符串product.ProductName中的' 替换为 \'
    string str=string.Format("return confirm {0} ",变量);
    就相当于
    str="return confirm”+变量;