protected void GV_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string type = e.Row.Cells[0].Text.ToString(); LinkButton linkbtn = e.Row.FindControl("linkbtnDel") as LinkButton; linkbtn.Visible = false;
if (type == "BEGIN")
{
linkbtn.Visible = true;
}
}
}哪位大哥能帮我具体解释下上面每句代码的意思?特别是if (e.Row.RowType == DataControlRowType.DataRow)
谢谢了!
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string type = e.Row.Cells[0].Text.ToString(); LinkButton linkbtn = e.Row.FindControl("linkbtnDel") as LinkButton; linkbtn.Visible = false;
if (type == "BEGIN")
{
linkbtn.Visible = true;
}
}
}哪位大哥能帮我具体解释下上面每句代码的意思?特别是if (e.Row.RowType == DataControlRowType.DataRow)
谢谢了!
他的意思就是:如果当前取到的gridview的行是绑定数据的行,也就是显示数据的行。
这个是必须的判断语句,在GrivView的数据行dataRow,才能执行数据绑定时的事件.
string type = e.Row.Cells[0].Text.ToString();
取得这行的第一个元素(索引0)的文本内容
LinkButton linkbtn = e.Row.FindControl("linkbtnDel") as LinkButton;
找到LinkButton,因运行后ID变成了ClientID,所以要用FindControl方法找到这个控件再操作
有表头Header
有表中数据DataRow
有页脚Footer
有分页Pager
等等!你的DataControlRowType.DataRow是对表中数据进行处理
protected void GV_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//只对表中的数据行进行处理
{
string type = e.Row.Cells[0].Text.ToString();//得到当前行第一个单元格的值 LinkButton linkbtn = e.Row.FindControl("linkbtnDel") as LinkButton;//找到linkbtnDel控件 linkbtn.Visible = false;//让控件显示状态为隐藏
if (type == "BEGIN")//当前行第一个单元格的值为BEGIN的时候
{
linkbtn.Visible = true;//linkbtn状态为显示
}
}
}