在WEB页面里
<asp:BoundColumn DataField="Mobile" HeaderText="手机"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="验证">
<ItemTemplate>
<asp:Label ID="lblVali" Runat="server" Text='<%# DataBinder.Eval(Container,"DataItem.Validate_Status")%>'>
</asp:Label>
<asp:LinkButton CommandName="Validate" Runat="server" ID="lbtn" Text="验证" ForeColor="#3300ff"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
是这样的.我想根据Label.Text值,来控制LinkButton的显示.如果是Label显示"已" LINKButton就不显示.于是我在ItemDataBound事件中这样写.
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
TableCell myTableCell;
myTableCell=e.Item.Cells[8];
Label Lb1=(Label)myTableCell.FindControl("lblSend");
string abd=Lb1.Text.Trim();
if(Lb1.Text.Trim()=="已")
{
((LinkButton)myTableCell.Controls[1]).Visible=false;
}
}
可是不行啊,((LinkButton)myTableCell.Controls[1]).Visible=false;找不到引用对象.ItemCreate事件也不行.根本不执行if(Lb1.Text.Trim()=="已").晕了.

解决方案 »

  1.   

    你要了解ItemDataBound发生的时间。这时DataGrid还未建立完成。
      

  2.   

    用e.Item.FindControl("lblVali")来找Label控件,e.Item.FindControl("lbtn")来找LinkButton控件。
      

  3.   

    天涯:不好使.
    我这样试了.仍然照常显示.
    if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
    {
    if(((Label)e.Item.FindControl("lblSend")).Text.Trim()=="已")
    {
                        ((LinkButton)e.Item.FindControl("lbtnSend")).Visible=false;
    }}
      

  4.   

    <asp:LinkButton CommandName="Validate" Runat="server" ID="lbtn" Text="验证" ForeColor="#3300ff" Visible='<%# DataBinder.Eval(Container, "DataItem.Validate_Status").ToString()!="已"%>'></asp:LinkButton>
    很难吗?这样不可以吗?
      

  5.   

    stoneallen(我不想说,我很亲切) 
    你那种方法也不好使
      

  6.   

    单步调试看看,可以把Row取出来看的啊,看看为什么没找到
      

  7.   

    stoneallen(我不想说,我很亲切) 
    你那种方法也不好使---------------------------
    怎么不好使啊?我在我的机上可是测试通过的哦
      

  8.   

    不好使啊,显示己了.还是显示按扭
    <asp:TemplateColumn HeaderText="发送">
    <ItemTemplate>
    <asp:Label ID="lblSend" Runat="server" Text='<%# DataBinder.Eval(Container,"DataItem.Send_Status")%>'>
    </asp:Label>
    <asp:LinkButton CommandName="Send" Runat="server" ID="lbtnSend" Text="发送" ForeColor="#3300ff" Visible='<%# DataBinder.Eval(Container,"DataItem.Send_Status").ToString()!="已"%>'></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateColumn>
      

  9.   

    <asp:LinkButton CommandName="Validate" Runat="server" ID="lbtn" Text="验证" ForeColor="#3300ff" Visible='<%# GetStatus(DataBinder.Eval(Container, "DataItem.Validate_Status").ToString())%>'></asp:LinkButton>
    后台:
    protected bool GetStatus(string str)
    {
        if(str == "已")
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    如果真的不好使,还可以用上面方法,我觉得实现的方法挺多的。
      

  10.   

    我的脑子让驴给踢了.真笨死了.咋就没想到呢. stoneallen(我不想说,我很亲切):谢谢你.你的方法好使.我会给你分的.谢谢了.