母板页中FindControl的问题............
页面:
<%@ Page AutoEventWireup= "true " CodeFile= "WEB_Case02b.aspx.cs " Inherits= "Case_WEB_Case02b "
Language= "C# " MasterPageFile= "~/MasterPages/Default.master " %>
........
<asp:Content ID= "Content3 " ContentPlaceHolderID= "Contentbar " runat= "Server ">
<asp:GridView ID= "GridView1 " ...>
<Columns>
<asp:TemplateField HeaderText= "操作 ">
<ItemTemplate>
<asp:LinkButton ID= "bt_Priview " runat= "server " CausesValidation= "False " Text= "查看 "> </asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Content>
在后台cs代码中想控制bt_Priview的一些属性,现在要先FindControl这个控件,如何做?
尝试过
LinkButton myctrl = Master.FindControl( "bt_Priview ");
Control myctrl = FindControl( "bt_Priview ");
Control myctrl = Master.FindControl( "bt_Priview ");
此时myctrl里面都是null,找不到控件...........
------解决方案--------------------LinkButton myctrl = GridView1.FindControl( "bt_Priview ");
试试这个,要用包着他的控件FindControl
------解决方案--------------------LinkButton l = (LinkButton)Master.FindControl( "bt_Priview ");
这样应该没有问题.
建议给MASTER加个属性.
在母版页代码加上:
public LinkButton Bt_preview
{get{return bt_Priview;}}
在要使用的页面调用MASTER 的属性
Master.Bt_preview就行了.
------解决方案--------------------你找的控件是不是在ContentPlaceHolder中啊
试试
Master.FindControl( "ContentPlaceHolderID ").FindControl( "GridView1 ")....;
------解决方案--------------------要使用的页面还在加上
<%@ MasterType TypeName= "MasterPage " %>
指令, 抱歉啊, 忘了.
------解决方案--------------------protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lbtn = (lbtn)e.Row.Cells[单元格索引].FindControl( "btn_Priview ");
lbtn.ToolTip = "查看 ";
}
}
------解决方案--------------------LinkButton lbtn = (LinkButton)e.Row.Cells[单元格索引].FindControl( "btn_Priview ");