日期:2014-05-18 浏览次数:20607 次
LinkButton <asp:LinkButton ID="lb1" Label <asp:Label ID="lab1" GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton lb1 = (LinkButton)e.Row.FindControl("lb1"); Label lab1 = (Label)e.Row.FindControl("lab1"); if (true) { lb1.Visible = true; lab1.Visible = false; } else { lb1.Visible = false; lab1.Visible = true; } } }
------解决方案--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if(你要加LinkButton) { LinkButton lb = new LinkButton(); lb.Text = "你要显示的字"; e.Row.Cells[2].Controls.Add(lb);//在第3列加LinkButton } else if(你要加Label) { //参照上面 } } }
------解决方案--------------------
这就需要用到GrivView的RowDataBound事件了:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { LinkButton lb=e.Row.Cells.FindControl("LinkButton1") as LinkButton; Label label=e.Row.Cells.FindControl("Label1") as Label; if(你的逻辑判断) { lb.Visible=true; label.Visible=false; } else { lb.Visible=false; label.Visible=true; } }
------解决方案--------------------
这个需要重写模板列的接口实现。
挺复杂的。