关于Dataview删除操作的两个问题
1.dataview中的RowDeleted不执行,只执行RowDeleting?Dataview的属性如下
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%" OnPageIndexChanging="GridView2_PageIndexChanging" OnRowDeleted="GridView2_RowDeleted" OnRowDeleting="GridView2_RowDeleting" OnRowDataBound="GridView2_RowDataBound" >
2.我想让删除时候提示删除的记录名称
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && this.GridView2.EditIndex != e.Row.DataItemIndex)
{
int index = e.Row.RowIndex;
GridViewRow gvr = GridView2.Rows[index];
//取得当前行第二个单元格中的文字
string str1 = gvr.Cells[2].Controls[0].ToString();
((LinkButton)(e.Row.Cells[6].Controls[0])).Attributes.Add("onclick", "return confirm('确认删除名称为'" + str1 + "'吗?');");
}
}
载入页面的时候显示index 出错,不知道是什么原因导致?
------解决方案--------------------//取得当前行第二个单元格中的文字
string str1 = gvr.Cells[2].Controls[0].ToString(); 是错的
如果第3列没有控件的话
string str1 = gvr.Cells[2].Text;
有的话
string str1 = (gvr.Cells[2].Controls[0] as 控件).Text
------解决方案--------------------1楼正解````````
gvr.Cells[2].Controls[0] 得到的只是Controls对象
------解决方案--------------------protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow )
{
foreach(GridViewRow gvr in GridView2.Rows)
{
LinkButton lt=(LinkButton)gvr.FindControl("linkbuttonid");
if(lt!=null)
{
string str1 = gvr.Cells[2].Text;
lt.Attributes.Add("onclick", "return confirm('确认删除名称为'" + str1 + "'吗?');");
}
}
}
}
结构是没有错的,有可能有语法的错误
你改改应该就可以了
------解决方案--------------------ding