asp.net - SelectItemTemplate 不起作用

asp.net - SelectItemTemplate doesn't work

提问人:Semyon Labzov 提问时间:9/16/2018 最后编辑:Semyon Labzov 更新时间:9/16/2018 访问量:29

问:

我有两张桌子。首先工作正常 - 如果按钮 ID=“Button1” CommandName=“Select” 按下的选定项目变为红色。但是,如果我按下它自己的按钮 ID=“Button2” CommandName=“Select”,第二个表就不会做同样的事情。

第一个表 listView ID=“ListViewGrSDtudents”

第二个表 listView ID=“ListViewGroups”

现在有人为什么它不起作用吗?

这是我的 .aspx 代码:

<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <!-- Таблица групп -->
        <div>
            <asp:ListView ID="ListViewGroups"
                runat="server"
                ItemType="BD_Class_Library.studentGroup"
                DataKeyNames="groupId"
                SelectMethod="GetStudGroups"
                InsertMethod="InsertStudGroup"
                UpdateMethod="UpdateGroup"
                DeleteMethod="DeleteGroup"
                OnSelectedIndexChanged="ListViewGroups_SelectedIndexChanged">

                <InsertItemTemplate>
                    <tr style="background-color: yellowgreen">
                        <td></td>
                        <td>
                            <input id="groupName" runat="server" value="<%# BindItem.groupName %>" /></td>

                        <td>
                            <asp:Button ID="Button1" Width="100%" CommandName="Insert" runat="server" Text="Вставить" />
                        </td>
                    </tr>
                </InsertItemTemplate>

                <EditItemTemplate>
                    <tr style="background-color: yellow">
                        <td><%# Item.groupId %></td>
                        <td>
                            <input id="groupName" runat="server" value="<%# BindItem.groupName %>" /></td>
                        <td>
                            <asp:Button CommandName="Update" runat="server" Text="Сохранить" />
                            <asp:Button CommandName="Cancel" runat="server" Text="Отмена" />
                        </td>
                    </tr>
                </EditItemTemplate>


                <LayoutTemplate>
                    <table border="1">
                        <tr style="background-color: darkgray">
                            <th>ID</th>
                            <th>Группа</th>

                            <th></th>
                        </tr>
                        <tr id="itemPlaceholder" runat="server"></tr>
                    </table>
                </LayoutTemplate>
                <SelectedItemTemplate>
                    <tr style="background-color: red">
                        <td><%# Item.groupId %></td>
                        <td><%# Item.groupName %></td>
                        <td>
                            <asp:Button CommandName="Edit" runat="server" Text="Изменить" />
                            <asp:Button CommandName="Delete" runat="server" Text="Удалить" />
                        </td>
                    </tr>

                </SelectedItemTemplate>

                <ItemTemplate>
                    <tr style="background-color: grey">
                        <td><%# Item.groupId %></td>
                        <td><%# Item.groupName %></td>
                        <td>
                            <asp:Button CommandName="Select" runat="server" Text="Выбрать" />
                            <asp:Button CommandName="Edit" runat="server" Text="Изменить" />
                            <asp:Button CommandName="Delete" runat="server" Text="Удалить" />
                        </td>
                    </tr>
                </ItemTemplate>


            </asp:ListView>
        </div>
        <div>
            <asp:ListView
                ID="ListViewGrSDtudents"
                runat="server"
                ItemType="BD_Class_Library.student"
                DataKeyNames="studId"
                OnSelectedIndexChanging="ListViewGrSDtudents_SelectedIndexChanging"
                OnSelectedIndexChanged="ListViewGrSDtudents_SelectedIndexChanged">

                <SelectedItemTemplate>
                    <tr style="background-color: red">
                        <td><%# Item.studId %></td>
                        <td><%# Item.studFam %></td>
                        <td><%# Item.studName %></td>
                        <td><%# Item.studOtc %></td>
                        <td><%# Item.studBiletNum %></td>
                    </tr>
                </SelectedItemTemplate>

                <ItemTemplate>
                    <tr style="background-color: grey">
                        <td><%# Item.studId %></td>
                        <td><%# Item.studFam %></td>
                        <td><%# Item.studName %></td>
                        <td><%# Item.studOtc %></td>
                        <td><%# Item.studBiletNum %></td>
                        <td><asp:Button ID="Button2" CommandName="Select" runat="server" Text="Выбрать" /></td>


                    </tr>
                </ItemTemplate>
                <LayoutTemplate>
                    <table border="1" style="width: 60%">
                        <tr id="groupPlaceholder" runat="server"></tr>
                        <tr style="background-color: aqua">
                            <th>ID студента</th>
                            <th>Фамилия</th>
                            <th>Имя</th>
                            <th>Отчество</th>
                            <th>Студ. билет</th>

                        </tr>
                        <tr id="itemPlaceholder" runat="server" itemplaceholderid="itemPlaceholderStudent"></tr>
                    </table>
                </LayoutTemplate>

                <EmptyDataTemplate>
                    <table border="1" style="width: 60%">
                        <tr style="background-color: aqua">
                            <th>ID студента</th>
                            <th>Фамилия</th>
                            <th>Имя</th>
                            <th>Отчество</th>
                            <th>Студ. билет</th>
                            <th></th>
                        </tr>
                        <tr style="background-color: grey">
                            <td colspan="5" style="text-align: center">В данной группе нет студентов</<td>
                        </tr>
                    </table>
                </EmptyDataTemplate>
            </asp:ListView>
        </div>


    </form>

</body>
</html>

event - ListViewGrSDtudents_SelectedIndexChanged代码:

    protected void ListViewGrSDtudents_SelectedIndexChanged(object sender, EventArgs e)
    {
        int selStudent = (int)ListViewGrSDtudents.SelectedDataKey.Value;
        Session["SelectedStudent"] = selStudent;
        Session["SelectedStudentIndex"] = ListViewGrSDtudents.SelectedIndex;
        Response.Redirect("~/Default.aspx");

    }

描述 第 1 部分

描述 第 2 部分

C# asp.net XHTML

评论

0赞 Alex Kudryashev 9/16/2018
itemplaceholderid属性不属于 itempaceholder 本身。ListView
0赞 Semyon Labzov 9/16/2018
@AlexKudryashev,感谢您的回答,但不明白我该如何解决它?
0赞 Alex Kudryashev 9/16/2018
只需删除itemplaceholderid="itemPlaceholderStudent"
0赞 Semyon Labzov 9/16/2018
@AlexKudryashev,按钮无论如何都不起作用:(
0赞 Alex Kudryashev 9/16/2018
检查你的和处理程序。OnSelectedIndexChangingOnSelectedIndexChanged

答: 暂无答案