当前位置: 代码迷 >> ASP.NET >> ListView控件相关有关问题
  详细解决方案

ListView控件相关有关问题

热度:1803   发布时间:2013-02-25 00:00:00.0
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">星期二</th>                                        <th runat="server">星期三</th>                                        <th runat="server">星期四</th>                                        <th runat="server">星期五</th>                                        <th runat="server">星期六</th>                                        <th runat="server">星期日</th>                                    </tr>                                    <tr ID="groupPlaceholder" runat="server">                                    </tr>                                </table>                            </td>                        </tr>                    </table>                </LayoutTemplate>            </asp:ListView>
  相关解决方案