数据列表给错误的ajax

数据列表给错误的ajax

本文介绍了数据列表给错误的ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个放在内容占位符内部的数据列表控件.

I have a data list control which is placed inside a content place holder.

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
    <asp:ScriptManager ID="MainScriptManager" runat="server" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:DataList ID="dlProdocut" runat="server" RepeatColumns="3" EditItemIndex="-1"

                RepeatDirection="Horizontal" OnItemDataBound="dlProdocut_ItemDataBound">
                <ItemTemplate>
                    <asp:Table ID="Table1" runat="server" border="0" CellSpacing="0" CellPadding="0">
                        <asp:TableRow>
                            <asp:TableCell Height="10" HorizontalAlign="Center" VerticalAlign="Top">

                            </asp:TableCell>
                        </asp:TableRow>
                        <%--Image--%>
                        <asp:TableRow>
                            <asp:TableCell Height="150" Width="7" HorizontalAlign="left" VerticalAlign="top">
                                <asp:HyperLink ID="hyrProductImg" runat="server">
                              <img alt='<%# DataBinder.Eval(Container.DataItem,"Title")%>' src="../images/<%# DataBinder.Eval(Container.DataItem,"SmallImage") %>" border="0" width="226" height="166" />
                                </asp:HyperLink>
                            </asp:TableCell>
                            <asp:TableCell Width="5">&nbsp;&nbsp;</asp:TableCell>
                        </asp:TableRow>
                        <%--Title--%>
                        <asp:TableRow>
                            <asp:TableCell Height="45" Width="7" CssClass="product-name" HorizontalAlign="Center"

                                VerticalAlign="Top">
                            <strong>&nbsp;<%# DataBinder.Eval(Container.DataItem, "Title")%></strong>
                            </asp:TableCell>
                        </asp:TableRow>
                        <%--ShortDescription--%>
                        <asp:TableRow>
                            <asp:TableCell Width="7" HorizontalAlign="Justify" VerticalAlign="Top" CssClass="testimonial-text">
                                <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ShortDescription")%>'></asp:Label>
                            </asp:TableCell>
                        </asp:TableRow>
                        <%--Read More--%>
                        <asp:TableRow>
                            <asp:TableCell HorizontalAlign="Left">
                                <asp:HyperLink ID="lnkProductDetails" CssClass="read-more" runat="server">Read More &rarr;</asp:HyperLink>
                            </asp:TableCell>
                        </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableCell Height="60" HorizontalAlign="Justify" VerticalAlign="Top" CssClass="testimonial-text">

                            </asp:TableCell>
                        </asp:TableRow>
                    </asp:Table>
                </ItemTemplate>
            </asp:DataList>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="dlProdocut" />
            <asp:AsyncPostBackTrigger ControlID="btnNext" />
        </Triggers>
    </asp:UpdatePanel>
    <asp:Label ID="lblPage" runat="server" Text="" />
    <asp:Button ID="btnPrevious" runat="server" Text="&lt;&lt;" />
    <asp:Button ID="btnNext" runat="server" Text="&gt;&gt;" OnClick="btnNext_Click" />
    <asp:Panel ID="BottomPager_Panel" runat="server">
    </asp:Panel>
</asp:Content>



单击下一步按钮时,我正在控件上进行分页并导航到下一页.
在页面加载中,我正在这样做



On click of next button i am doing paging on the control and navigating to the next page.
On page load i am doing this

if (!IsPostBack)
        {
            pageCount = 1;
            PageNo = 1;
            startPage = 6 * (PageNo - 1) + 1;
             lastPage = startPage + 5;
             bindDataList();
        }



这是我的bindDataList代码



This is my code for bindDataList

public void bindDataList()
    {

        string source = ConfigurationManager.ConnectionStrings["Cad-B"].ToString();
        SqlConnection con = new SqlConnection(source);
        SqlCommand cmd = new SqlCommand("sp_GetProductPagingByMenuId", con);
        //cmd.CommandType = CommandType.StoredProcedure;
        //cmd.CommandText = "sp_GetProductPagingByMenuId";
        con.Open();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@startPage", startPage);
        cmd.Parameters.Add("@lastPage", lastPage);
        SqlDataReader dr =    cmd.ExecuteReader();
        DataTable dt = new DataTable();
        dt.Load(dr);

        dlProdocut.DataSource = dt;
        dlProdocut.DataBind();
    }




在单击下一步按钮时,我编写了以下代码




On click of next button i have written the following code

protected void btnNext_Click(object sender, EventArgs e)
    {
        dlProdocut.DataSource = null;
        dlProdocut.DataBind();
        pageCount++;
        PageNo = pageCount;
        startPage = 6 * (PageNo - 1) + 1;
        lastPage = startPage + 5;
        bindDataList();
    }



我面临的问题是,它每次都向我显示与第一次在页面上加载的内容相同的内容.当我调试代码时,我可以看到数据列表已加载了新记录,但未在页面上反映出来,因此我尝试了删除缓存,但它确实有所帮助.当我从触发器部分中删除下一个按钮的那一刻,它给了我适当的记录,但是整个页面都在发回我不想要的东西.这是已删除的代码



Problem i am facing is that it every time shows me the same content that is loaded the first time on the page. When i debug the code i can see that the data list is loaded with the new records but it is not reflected on the page i tried removing caching but it dint help. The moment i removed the next button from the trigger section it is giving me the proper record but the complete page is getting post back which i dont want. This is the removed code

<asp:AsyncPostBackTrigger ControlID="btnNext" />


请帮助我长期以来一直坚持下去.我是这项技术的新手.预先感谢.


Please help i am stuck with this since long. I am new to this technology. Thanks in advance.

推荐答案


<asp:UpdatePanel ID="UpdatePanel1" runat="server">


进入


into

<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMod="Conditional">



然后在您的点击事件中:



then in your click event:

UpdatePanel1.Update();




或者,如果不起作用,请尝试以下方法:




or if not work the try this one:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnNext" EventName="Click" />
&lt;asp:AsyncPostBackTrigger ControlID="dlProdocut" EventName="Click" /&gt;

 </Triggers>
 <ContentTemplate>


....
....

希望对您有所帮助.

问候,

代数


....
....

Hope this could help.

Regards,

Algem


这篇关于数据列表给错误的ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 13:12