在做一个项目的流程管理,用到GridView,要终止流程,点击"终止流程",要先弹出确认对话框,如果点对话框中"是",则转向结束页面进行流程终止处理,点否,则回到原页面.
参考了网上若干的有关"gridview删除确认提示框"实现,结合项目实际,我是如下进行的:
1.HTML页面,在GridView中添加如下代码:
<asp:CommandField HeaderText ="操作" SelectText ="终止" ShowSelectButton ="True" >
<ItemStyle Width ="40px" />
</asp:CommandField>
2.后台代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[10].Visible = false;
}
if(e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[10].Text == "10" || e.Row.Cells[10].Text == "12" || e.Row.Cells[10].Text == "14" || e.Row.Cells[10].Text == "15" || e.Row.Cells[10].Text == "16")
{
e.Row.Cells[9].Attributes.Add("onclick", "javascript:alert('该流程已结束.');");
}
else
{
e.Row.Cells[9].Attributes.Add("onclick", "javascript:if(confirm('你确认要结束流程/"" + e.Row.Cells[2].Text + "/"吗?')){location='breakFlow.aspx?applyId=" + e.Row.Cells[0].Text + "';}else{location='applyFlowManager.aspx';}");
}
e.Row.Cells[10].Visible = false;
}
}
3.其中的Cells[9],是第十列, <asp:CommandField HeaderText="终止" SelectText="终止" ShowSelectButton="True" >;
Cells[10],是第十一列,<asp:BoundField DataField="status_value" HeaderText="状态值" />,在GridView1中 Visible="True";
由于状态值只是数字,所在 GridView1_RowDataBound 事件中将Cells[10] 的HeaderTest 和 值又设为了隐藏;
Cells[2]是第三该流程的主题 ,
Cells[0]是我的主键id,用来传递到下一个页面的值,
Cells[0]列不能是隐藏的,如果隐藏了就取不到相应的id值了.
参考了网上若干的有关"gridview删除确认提示框"实现,结合项目实际,我是如下进行的:
1.HTML页面,在GridView中添加如下代码:
<asp:CommandField HeaderText ="操作" SelectText ="终止" ShowSelectButton ="True" >
<ItemStyle Width ="40px" />
</asp:CommandField>
2.后台代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[10].Visible = false;
}
if(e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[10].Text == "10" || e.Row.Cells[10].Text == "12" || e.Row.Cells[10].Text == "14" || e.Row.Cells[10].Text == "15" || e.Row.Cells[10].Text == "16")
{
e.Row.Cells[9].Attributes.Add("onclick", "javascript:alert('该流程已结束.');");
}
else
{
e.Row.Cells[9].Attributes.Add("onclick", "javascript:if(confirm('你确认要结束流程/"" + e.Row.Cells[2].Text + "/"吗?')){location='breakFlow.aspx?applyId=" + e.Row.Cells[0].Text + "';}else{location='applyFlowManager.aspx';}");
}
e.Row.Cells[10].Visible = false;
}
}
3.其中的Cells[9],是第十列, <asp:CommandField HeaderText="终止" SelectText="终止" ShowSelectButton="True" >;
Cells[10],是第十一列,<asp:BoundField DataField="status_value" HeaderText="状态值" />,在GridView1中 Visible="True";
由于状态值只是数字,所在 GridView1_RowDataBound 事件中将Cells[10] 的HeaderTest 和 值又设为了隐藏;
Cells[2]是第三该流程的主题 ,
Cells[0]是我的主键id,用来传递到下一个页面的值,
Cells[0]列不能是隐藏的,如果隐藏了就取不到相应的id值了.