是否可以隐藏位于ListView中的asp面板?

时间:2014-05-17 23:44:01

标签: c# asp.net

当我按下编辑按钮编辑数据库中的内容时,我希望能够隐藏面板“可见”但我在这方面遇到了一些麻烦。我是asp和amp;编码的新手。 c#所以很多语法很难习惯。我在构建网站时收到此错误;

System.NullReferenceException: Object reference not set to an instance of an object.

这是我的aspx代码

<asp:ListView ID="displayedit" runat="server" 
            DataSourceID="newseditrows" 
            DataKeyNames="id" 
            OnItemUpdated="displayedit_ItemUpdated" 
            OnItemEditing="displayedit_ItemEditing" 
            OnItemCanceling="displayedit_ItemCanceling">

            <AlternatingItemTemplate>
                <asp:Panel ID="visible" runat="server">
                <h2>                    
                <asp:Label runat="server" Text='<%# Eval("postheadline") %>' ID="headlinetitle" /></h2>
                <h3><asp:Label runat="server" Text='<%# Eval("sportname") %>' ID="Label2" /></h3>
                <asp:Image ImageUrl='<%# "../images/" + Eval("postimage") %>' runat="server" ID="Label1" CssClass="img-responsive" Height="210px" Width="616px" />
                <div class="singe_desc">
                <p><b>
                    <asp:Label Text='<%# Eval("postlead") %>' runat="server" ID="leadLabel" /></b></p>
                <p>
                    <asp:Label Text='<%# Eval("postparagraph") %>' runat="server" ID="paragraphlabel" /></p>
                <br />
                <ul class="links">
                    <li><a href="#"><i class="blog_icon1"></i>
                <br>
                <span>
                    <asp:Label Text='<%# Eval("postdate") %>' runat="server" ID="dateLabel" /></span></a></li>
                    <li><a href="#"><i class="blog_icon2"></i>
                <br>
                <span>
                    <asp:Label Text='<%# Eval("postauthorID") %>' runat="server" ID="authorIDLabel" /></span></a></li>
                </ul>
                <br />
                <div class="btn_blog">
                        <asp:HyperLink ID="HyperLink2"
                            runat="server"
                            Text='<%# "Read More" %>'
                            NavigateUrl='<%# "../article.aspx?articleid=" + Eval("id") %>' />
                </div>
                <div class="clear"></div>
                </div>
                <asp:Button runat="server" CommandName="Edit" Text="Edit" ID="EditButton" />
                <br /></asp:Panel>

这是我的C#代码

protected void displayedit_ItemEditing(object sender, ListViewEditEventArgs e)
    {
        info.Text = "I am editing";
        Panel mydiv = (Panel)displayedit.EditItem.FindControl("visible");
        mydiv.Visible = false;

0 个答案:

没有答案