码东东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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
    • ¥15 怎么让wx群机器人发送音乐
    • ¥15 fesafe材料库问题
    • ¥35 beats蓝牙耳机怎么查看日志
    • ¥15 Fluent齿轮搅油
    • ¥15 八爪鱼爬数据为什么自己停了
    • ¥15 交替优化波束形成和ris反射角使保密速率最大化
    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功