РЕДАКТИРОВАТЬ: я нашел причину проблемы, но я не знаю, почему, и я не знаю, как это исправить. Я использую JQuery Mobile для темы своего сайта, и когда я удаляю эту строку:
<div data-role="page" data-theme="a">
Я могу заставить репитер работать правильно. Кто-нибудь знает, как я могу сохранить свою тему и заставить этот репитер работать?
Хорошо, у меня есть репитер, как это:
<asp:Repeater ID="Repeater1" runat="server" onitemcommand="Repeater1_ItemCommand" EnableViewState="true">
<ItemTemplate>
<li>
<asp:LinkButton ID="Button1" runat="server" Text='<%# Container.DataItem %>' CommandName="Redirect" />
</li>
</ItemTemplate>
</asp:Repeater>
И код за этим выглядит так
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Redirect")
{
Session["contact"] = ((LinkButton)e.CommandSource).Text;
Response.Redirect("Contact_Details.aspx");
}
}
И если я перейду прямо на эту страницу (без ссылки на нее с другой страницы), повторитель запустит ItemCommand. Но, если моя страница входа перенаправляется обратно на эту страницу или я просто нажимаю ссылку на эту страницу с другой страницы, команда itemcommand никогда не срабатывает при нажатии на кнопки ссылки. Любые подсказки относительно того, почему это так?
РЕДАКТИРОВАТЬ: Полный код для этой страницы:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Contacts.aspx.cs" Inherits="WebApplication3.Contacts" %>
<%@ MasterType VirtualPath = "~/Site1.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:Repeater ID="Repeater1" runat="server" onitemcommand="Repeater1_ItemCommand" EnableViewState="true">
<HeaderTemplate> <ul data-role='listview' data-theme='c' data-inset='true'>
<li data-role="list-divider"><center><h1>Contacts</h1></center></li></HeaderTemplate>
<ItemTemplate>
<li>
<asp:LinkButton ID="Button1" runat="server" Text='<%# Container.DataItem %>' CommandName="Redirect" />
</li>
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
</asp:Content>
При загрузке страницы я подключаюсь к веб-сервису, который подключается к обмену и возвращает массив. Я делаю быстрое преобразование массива в массив, тогда остальная часть кода:
//Converts the array grabbed from the webservice to an arraylist
ArrayList testList = ArrayList.Adapter(contactsList);
Repeater1.DataSource = testList;
Repeater1.DataBind();
Repeater1.ItemCommand += new RepeaterCommandEventHandler(Repeater1_ItemCommand);
}