关于GridView中为模板列动态赋值的有关问题

关于GridView中为模板列动态赋值的问题
需求是这样的,有GridView1一个,GridView1中有模板列一个,在数据加载过程中,会根据逻辑代码的判断来决定放哪个控件,其中的控件包括 一个LinkButton控件或者Label控件,您能否写一段代码给我呢,谢谢!

------解决方案--------------------
假设两个控件都放,两个控件初始都隐藏。
在行绑定事件中写
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(你的逻辑判断)
{
e.Row.Cells[CellIndex].Controls[1].Visible = true;
}
else
{
e.Row.Cells[CellIndex].Controls[2].Visible = true;
}
}
------解决方案--------------------
C# code
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.Cells[CellIndex].Controls[1].Visible = true;
}
else
{
e.Row.Cells[CellIndex].Controls[2].Visible = true;
}
}

------解决方案--------------------
在RowDataBound里面加不就好了:
C# code

 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事件了:
C# code

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;
    } 
}

------解决方案--------------------
这个需要重写模板列的接口实现。

挺复杂的。