关于GridView控件的问题!
请问如何在页面加载的时候为GridView的模板列动态绑定一个LinkButton控件。注:不是直接拖控件到模板列内。
[解决办法]
在RowDataBound事件里可以做。
[解决办法]
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//e.Row.Cells[0];//第1列不太明白楼主究竟要得到什么,
//查找控件
//LinkButton lb = (LinkButton)e.Row.Cells[0].FindControl("控件ID");
}
}
[解决办法]
RowDataBound是绑定事件,每帮顶一行,触发一次
[解决办法]
这就需要用到GrivView的RowDataBound事件了:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { 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; } } }
[解决办法]
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
LinkButton linkb = new LinkButton();
linkb.ID = "LinkButton1";
linkb.Text = "haha";
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[CellIndex].Controls.Add(linkb);
}
}
[解决办法]
顶6楼
[解决办法]