码东东666 2017-04-17 02:25
浏览 720

UpdatePanel 在Listview嵌套Listview中失效

Listview嵌套Listview

UpdatePanel 实现局部刷新

第二个 Listview中有一个RadioButtonList,选择NG时,后台实现备注文本框必填。这个动作需要局部刷新,而不是刷新整个页面,目前这个方法是整体刷新。
HTML代码如下:

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Laser_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>TEST</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div>
            <asp:Literal ID="Literal1" runat="server"></asp:Literal>
            <table class="TbTemplate">
                <tr>
                    <td colspan="8">
                        <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
                            <ContentTemplate>
                                <asp:ListView ID="ListView1" runat="server"
                                    OnItemDataBound="ListView1_ItemDataBound">
                                    <LayoutTemplate>
                                        <table style="width: 100%; border-collapse: collapse">
                                            <tr id="Tr1" class="LV1TbTh" runat="server" style="background-color: #3a90c9; color: #ffffff">
                                                <th class="LV1td1">检查项目</th>
                                                <th class="LV1td2">检查内容</th>
                                                <th class="LV1td3">检查结果</th>
                                                <th class="LV1td4">备注</th>
                                            </tr>
                                            <tr id="itemPlaceholder" runat="server">
                                            </tr>
                                        </table>
                                    </LayoutTemplate>
                                    <ItemTemplate>
                                        <tr class="LV1Item">
                                            <td class="LV1td1"><%# Eval("Item_Name") %></td>
                                            <td colspan="3">
                                                <asp:ListView ID="ListView2" runat="server" OnItemDataBound="ListView2_ItemDataBound">
                                                    <LayoutTemplate>
                                                        <table class="LV2itemPlaceholderContainer" style="width: 100%; border-collapse: collapse">
                                                            <tr>
                                                                <asp:PlaceHolder runat="server" ID="itemPlaceholder" />
                                                            </tr>
                                                        </table>
                                                    </LayoutTemplate>
                                                    <ItemTemplate>
                                                        <tr class="LV2TbItem">
                                                            <td class="LV1td2"><%# Eval("Content_Name") %></td>
                                                            <td class="LV1td3">
                                                                <div style="width: 80%; float: left">
                                                                    <asp:RadioButtonList ID="RadioButtonList_LV2" runat="server" RepeatDirection="Horizontal" Width="100%"
                                                                        OnTextChanged="RadioButtonList1_TextChanged" AutoPostBack="true">
                                                                        <asp:ListItem>OK</asp:ListItem>
                                                                        <asp:ListItem>NG</asp:ListItem>
                                                                        <asp:ListItem>NA</asp:ListItem>
                                                                    </asp:RadioButtonList>
                                                                </div>
                                                                <div style="width: 20%; float: left">
                                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="检查结果必选!"
                                                                        ControlToValidate="RadioButtonList_LV2" ValidationGroup="Laser_New_Submit" ForeColor="Red" Text="*"></asp:RequiredFieldValidator>
                                                                </div>
                                                            </td>
                                                            <td class="LV1td4">
                                                                <asp:TextBox ID="TextBox_LV2" runat="server" CssClass="LV1asptxt" TextMode="MultiLine" Rows="2" Height="48px"></asp:TextBox>
                                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="选择NG后必选!"
                                                                    ControlToValidate="TextBox_LV2" ValidationGroup="Laser_New_Submit" ForeColor="Red" Text="*" Enabled="false"></asp:RequiredFieldValidator>
                                                            </td>
                                                        </tr>
                                                    </ItemTemplate>
                                                </asp:ListView>
                                            </td>
                                        </tr>
                                    </ItemTemplate>
                                </asp:ListView>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </td>
                </tr>
            </table>
            <div style="margin-bottom: 10px; width: 99%">
                <asp:Button ID="Button1" runat="server" Text="提交" CssClass="btnsubmit" ValidationGroup="Laser_New_Submit" OnClick="Button1_Click" />
                <asp:ValidationSummary ID="ValidationSummary1" HeaderText="错误列表:" runat="server" EnableClientScript="true"
                    ShowMessageBox="true" ShowSummary="false" DisplayMode="BulletList" ValidationGroup="Laser_New_Submit" />
            </div>
        </div>
    </form>
</body>
</html>

后台代码部分:

 protected void RadioButtonList1_TextChanged(object sender, EventArgs e)
    {
        try
        {
            RadioButtonList rbl = sender as RadioButtonList;
            if (rbl != null)
            {
                ListViewDataItem LV1dataitem = rbl.Parent as ListViewDataItem;
                if (rbl.SelectedValue == "NG")
                {

                    ((RequiredFieldValidator)LV1dataitem.FindControl("RequiredFieldValidator2")).Enabled = true;
                }
                else
                {
                    ((RequiredFieldValidator)LV1dataitem.FindControl("RequiredFieldValidator2")).Enabled = false;
                }
            }
        }
        catch (Exception ex)
        {
            Literal1.Text = ex.ToString();
        }
    }

请各位大神帮忙看看:
1.为什么不能实现局部刷新,实际状况为整体页面刷新(测试过如果listview不嵌套,只有一个listview,最外面放一个UpdatePanel是起作用的,嵌套之后就不行了。)
2.还有什么方式实现,listview2中选择NG,备注项目必填!
图片说明

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 一个python博客项目的相关图例
    • ¥15 轮廓提取也提取不到,有没有别的方法,如何解决?
    • ¥50 Js和c++如何将含有图片的excel文件上传到后台服务器
    • ¥15 光电神经网络,FPGA
    • ¥20 通过防火墙出入站阻止游戏程序联网失效
    • ¥15 鼠标是可以在QT界面上移动的,但是热拔插鼠标无法移动了同时板子上是没问题的,如何解决?
    • ¥15 iframe嵌套显示问题
    • ¥20 【UE4】别人打包好的ue4游戏我该如何在自己的ue4引擎上运行
    • ¥15 power bi发布的链接地址打不开
    • ¥15 pip list列表中有库,但是编译时就显示缺少库