首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

为何ListView控件中ItemTemplate的 编辑 按钮点击时无效解决方案

2012-03-15 
为何ListView控件中ItemTemplate的 编辑 按钮点击时无效前台代码:C# codeasp:ListView IDListView1 ru

为何ListView控件中ItemTemplate的 编辑 按钮点击时无效
前台代码:

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="取消" />                        <br />                    </td>                </EditItemTemplate>                <GroupTemplate>                    <tr ID="itemPlaceholderContainer" runat="server">                        <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="编辑" />                        <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>


后台代码:
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;            }        }    } 



在加入后台这段代码前 编辑 按钮正常运行,加入后台这段代码后 编辑 按钮就点击无效了,怎么回事啊?

[解决办法]
参考:http://hi.baidu.com/crp8/blog/item/6ec8b3ec40c4b13b269791e9.html

热点排行