gridview怎么获取选中当前所在行的其他控件
展开全部
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//生成自动编号列
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Text = (e.Row.RowIndex + 1).ToString();
}
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
LinkButton lk = (LinkButton)e.Row.Cells[4].FindControl("LinkButton2");
if (lk != null)
lk.Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[3].Text + "\"吗?')");
//((LinkButton)e.Row.Cells[2].Controls[1]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
}
}
}
如代码 gridview 中 LinkButton lk = (LinkButton)e.Row.Cell[4].FindControl("LinkButton2"); 以ID 就可以获得当前值 但是 要在 GridView1_RowDataBound 才行
{
//生成自动编号列
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Text = (e.Row.RowIndex + 1).ToString();
}
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
LinkButton lk = (LinkButton)e.Row.Cells[4].FindControl("LinkButton2");
if (lk != null)
lk.Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[3].Text + "\"吗?')");
//((LinkButton)e.Row.Cells[2].Controls[1]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
}
}
}
如代码 gridview 中 LinkButton lk = (LinkButton)e.Row.Cell[4].FindControl("LinkButton2"); 以ID 就可以获得当前值 但是 要在 GridView1_RowDataBound 才行
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询