更新面板中的asp.net转发器数据绑定外部page_load

时间:2016-01-19 13:22:11

标签: asp.net updatepanel repeater

我在updatePanel asp.net中有转发器。当我在Page_load方法中运行databind()时,它工作正常。但是当Page_load之外的某些事件调用databind()时,转发器将被清除。 Databind()在这种情况下不起作用!这可能是什么原因? 这是代码......

这有效:

protected void Page_Load(object sender, EventArgs e)
{
    ........      
    populateCalendar(Int32.Parse(DDL_YearsList.SelectedValue), Int32.Parse(DDL_MonthsList.SelectedValue), Int32.Parse(DDL_EmployeesList.SelectedValue));

}

private void populateCalendar(int year, int month, int idEmploee)
{
.......     
    monthShower.DataSource = listWeeks;
    monthShower.DataBind();
}
protected void DDL_EmployeesList_SelectedIndexChanged(object sender, EventArgs e)
{

    //populateCalendar(Int32.Parse(DDL_YearsList.SelectedValue), Int32.Parse(DDL_MonthsList.SelectedValue), Int32.Parse(DDL_EmployeesList.SelectedValue));
}

当DDL_EmployeesList_SelectedIndexChanged被触发时,这不起作用:

protected void Page_Load(object sender, EventArgs e)
{
    ........      
   // populateCalendar(Int32.Parse(DDL_YearsList.SelectedValue), Int32.Parse(DDL_MonthsList.SelectedValue), Int32.Parse(DDL_EmployeesList.SelectedValue));

}

private void populateCalendar(int year, int month, int idEmploee)
{
.......     
    monthShower.DataSource = listWeeks;
    monthShower.DataBind();
}

protected void DDL_EmployeesList_SelectedIndexChanged(object sender, EventArgs e)
{

    populateCalendar(Int32.Parse(DDL_YearsList.SelectedValue), Int32.Parse(DDL_MonthsList.SelectedValue), Int32.Parse(DDL_EmployeesList.SelectedValue));
}

<asp:Repeater id ="monthShower" runat ="server"> <ItemTemplate> <custom:DayID="Day1" runat ="server" TblDay =<%# DataBinder.Eval(Container.DataItem, "Monday") %>></custom:Day> </ItemTemplate> </asp:Repeater>

1 个答案:

答案 0 :(得分:0)

所以我做了一个小测试并发布了代码

HTML:

<div id="test">
                <asp:DropDownList runat="server" ID="DropDownList1" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
                <asp:UpdatePanel runat="server">
                    <ContentTemplate>
                        <table>
                            <asp:Repeater runat="server" ID="repTeste" OnItemDataBound="repTeste_ItemDataBound">
                                <ItemTemplate>
                                    <tr>
                                        <td runat="server" id="tdTeste">

                                        </td>
                                    </tr>
                                </ItemTemplate>
                            </asp:Repeater>
                        </table>
                        </ContentTemplate>
                </asp:UpdatePanel>
            </div>

C# - 我在pageLoad中使用了pop()来填充ddl:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        populateCalendar(DropDownList1.SelectedValue, 2, 3);
    }
    private void populateCalendar(String year, int month, int idEmploee)
    {
        List<String> lis = new List<String>();
        lis.Add(year);

        repTeste.DataSource = lis;
        repTeste.DataBind();
    }
    private void pop()
    {
        ListItem li = new ListItem("1", "1");
        li.Attributes.Add("title", "1");
        DropDownList1.Items.Add(li);
        li = new ListItem("2", "2");
        li.Attributes.Add("t2itle", "2");
        DropDownList1.Items.Add(li);
        li = new ListItem("3", "3");
        li.Attributes.Add("ti3tle", "3");
        DropDownList1.Items.Add(li);
    }

    protected void repTeste_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        String inte = (String)e.Item.DataItem;

        HtmlTableCell td = (HtmlTableCell)e.Item.FindControl("tdTeste");
        td.InnerText = inte;
    }

它正确更新。 由于你没有发布你的html以及有人删除了我的帖子,我在这里为你发布了我的代码,你可以用它来比较它,或者你可以发布你的Html并生病看看。