日期:2014-05-17  浏览次数:20491 次

ListView控件相关问题
图1:

图2:

不加后台代码,点击“编辑”按钮,能转变成 图2 所示那样;

加上后台代码,点击 图1 箭头所示“编辑”按钮,没任何反应,此“编辑”按钮并非灰色。为什么按钮点击没反应啊?如何修复?

后台代码:
C# code
    protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            Label courseContentLabel = e.Item.FindControl("CourseContentLabel") as Label;
            Button editButton = e.Item.FindControl("EditButton") as Button;
            if (courseContentLabel.Text == "")
            {
                editButton.Enabled = false;
            }
        }
    }


前台代码:
C# code
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" 
                DataSourceID="EntityDataSource2" GroupItemCount="7" onitemdatabound="ListView1_ItemDataBound" 
                >
                <EditItemTemplate>
                    <td runat="server">
                        课程名称:
                        <asp:TextBox ID="CourseContentTextBox" runat="server" 
                            Text='<%# Bind("CourseContent") %>' />
                        教师:
                        <asp:TextBox ID="TeacherTextBox" runat="server" Text='<%# Bind("Teacher") %>' />
                        <br />
                        <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="更新" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="取消" CausesValidation="False" />
                        <br />
                    </td>
                </EditItemTemplate>
                <GroupTemplate>
                    <tr ID="itemPlaceholderContainer" runat="server">
                        <td></td>
                        <td ID="itemPlaceholder" runat="server">
                        </td>
                    </tr>
                </GroupTemplate>
                <ItemTemplate>
                    <td runat="server">
                        <asp:Label ID="CourseContentLabel" runat="server" 
                            Text='<%# Eval("CourseContent") %>' />
                        <asp:Label ID="TeacherLabel" runat="server" Text='<%# Eval("Teacher") %>' />
                        <br />
                        <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="编辑" CausesValidation="True" />
                        <br />
                    </td>
                </ItemTemplate>
                <LayoutTemplate>
                    <table runat="server" border="2">
                        <tr runat="server">
                            <td runat="server">
                                <table ID="groupPlaceholderContainer" runat="server" border="1">
                                    <tr runat="server">
                                        <th runat="server"></th>
                                        <th runat="server">星期一</th>
                                        <th runat="server&quo