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中给删除按钮增加提示的做法,最后一句我觉得有点复杂,不理解.能详细讲一下这句的运作流程吗?
{
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中给删除按钮增加提示的做法,最后一句我觉得有点复杂,不理解.能详细讲一下这句的运作流程吗?
</asp:LinkButton>如果是在模板中这样设置其属性,我想象上面一样可以有提示删除的字段的信息,怎么写?
string.Format("return confirm('Are you certain you want to delete the {0} product?');", product.ProductName.Replace("'", @"\'"))
如下面这个可以把你好,放到{0}里,把再见放到{1}里,当然你也可以增加多个参数,具体参看string.Format()方法
string.Format("{0}:{1}","你好,再见");
product.ProductName.Replace("'", @"\'")
这句代码的意思就是将 字符串product.ProductName中的' 替换为 \'
string str=string.Format("return confirm {0} ",变量);
就相当于
str="return confirm”+变量;