日期:2014-05-18  浏览次数:20395 次

GridView中TemplateField里的控件的属性问题
我先在GridView里添加了个TemplateField列
然后在模板编辑的ItemTemplate里加了个Image控件
也设置了GridView的DataKeyNames
但是我在用FindControl想设置Image控件的Visable属性的时候总是报:
用户代码未处理   System.NullReferenceException
    Message= "未将对象引用设置到对象的实例。 "
    Source= "App_Web_-8bq0x99 "
    StackTrace:
              在   index.SelectTreeId(String   ID)   位置   d:\My   Web\Visual   Studio   2005\MovieWeb\IndexRight.aspx.cs:行号   59
              在   index.Page_Load(Object   sender,   EventArgs   e)   位置   d:\My   Web\Visual   Studio   2005\MovieWeb\IndexRight.aspx.cs:行号   26
              在   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr   fp,   Object   o,   Object   t,   EventArgs   e)
              在   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object   sender,   EventArgs   e)
              在   System.Web.UI.Control.OnLoad(EventArgs   e)
              在   System.Web.UI.Control.LoadRecursive()
              在   System.Web.UI.Page.ProcessRequestMain(Boolean   includeStagesBeforeAsyncPoint,   Boolean   includeStagesAfterAsyncPoint)


我的前台是:

<asp:GridView   ID= "Show "   runat= "server "   CellPadding= "5 "   ForeColor= "#333333 "   GridLines= "None "
                                                        PageSize= "15 "   Width= "100% "   AutoGenerateColumns= "False "   ShowFooter= "True "   DataKeyNames= "ID "   OnDataBound= "Show_DataBound "   >
                                                        <FooterStyle   BackColor= "#507CD1 "   Font-Bold= "True "   ForeColor= "White "   />
                                                        <RowStyle   BackColor= "#EFF3FB "   Width= "100% "   />
                                                        <EditRowStyle   BackColor= "#2461BF "   />
                                                        <SelectedRowStyle   BackColor= "#D1DDF1 "   Font-Bold= "True "   ForeColor= "#333333 "   />
                              &nbs