日期:2014-05-17 浏览次数:20483 次
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; } } }
<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