在OnItemCommand方法中没有更新Repeater列表

时间:2015-07-17 17:35:32

标签: c# asp.net repeater

我有一个转发器控件。在转发器的OnItemCommand方法中,在执行某些操作后,我尝试刷新转发器列表,以便它可以显示更新的列表。但不知何故,转发器列表未在方法中更新。但是,当我重新加载页面时,转发器列表会使用最新的项目进行更新。

ASPX:

<asp:Label ID="Message1" runat="server" ForeColor="Blue" Text=""></asp:Label>
    <div id="ListingAgentsData" class="panel panel-default" style="width: 920px;">
        <asp:Repeater ID="rptagentList" runat="server" OnItemCommand="rptagentList_OnItemCommand">
            <HeaderTemplate>
                <table id="results1" cellpadding="4" cellspacing="1" width="100%">
                    <tr>
                        <td>
                            <strong>AgentID</strong>
                        </td>
                        <td>
                            <strong>Email</strong>
                        </td>
                        <td>
                            <strong>FullName</strong>
                        </td>
                        <td>
                            <strong>Driver License/Passport</strong>
                        </td>
                        <td>
                            <strong>Action</strong>
                        </td>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:Label ID="lblDayofweek" runat="server" Text='<%#Eval("AgentID")%>'></asp:Label>
                    </td>
                    <td>
                        <asp:Label ID="lblTime" runat="server" Text='<%#Eval("Email")%>'></asp:Label>
                    </td>
                    <td>
                        <asp:Label ID="lblCharges" runat="server" Text='<%#Eval("FullName")%>'></asp:Label>
                    </td>
                    <td>
                        <asp:Label ID="Label1" runat="server" Text='<%#Eval("DriverLicense")%>'></asp:Label>
                    </td>
                    <td>
                        <asp:LinkButton ID="ibtn" runat="server" Text="Approve" CommandName="Approve" CommandArgument='<%#Eval("AgentID")%>' />
                        <asp:LinkButton ID="LinkButton1" runat="server" Text="Reject" CommandName="Reject" CommandArgument='<%#Eval("AgentID")%>' />
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>

.CS:

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["Username"] == null)
        Response.Redirect("../Login/Default.aspx");
    else
    {
        Init();
    }
}

protected void rptagentList_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
    try
    {
        if (e.CommandName == "Approve")
        {
            int agentId = Convert.ToInt32(e.CommandArgument);
            GM gm = new GM();
            if (gm.ApproveListingAgent(agentId))
            {
                Message1.Text = "Listing Agent with ID:"+agentId+" is approved!";
                Init();
            }
        }
        else if (e.CommandName == "Reject")
        {

        }
    }
    catch (Exception ex)
    {
        throw ex;
    }

}

private void Init()
{
    ListingAgent Agent = new ListingAgent();
    DataTable dt = Agent.getPendingListingAgents();
    if (dt.Rows.Count > 0)
    {
        rptagentList.DataSource = dt;
        rptagentList.DataBind();
    }
}

我错过了什么?

请帮忙!

0 个答案:

没有答案