简体   繁体   中英

How to create dynamic server controls in C# and how to append more records from the database to repeater control without loading all once again

I have a repeater control on a page that I populate with 10 records from the database. There is a more button on the page; both are inside an update panel. The more button brings the next 10 records from the database. All I want to do is to append the new 10 records to the existing 10 records in the repeater. How would I do this?

I need it to work like Twitter and Facebook and load server side controls while appending new records to repeater control without paging.

This is my .aspx code:

<asp:repeater id="repStd" runat="server" onitemcommand="repStd_ItemCommand" 
    onitemdatabound="rptCore_ItemDataBound">                           
    <HeaderTemplate>                                                             
        <asp:Label ID="lnkStdName" runat="server" CommandName="Name" 
           CssClass="hrefclass">Name</asp:Label>                                        
    </HeaderTemplate>
    <ItemTemplate>
        <div class="headParent" id="STHeader" runat="server">                                                                          
            <asp:Label ID="lblStdName" runat="server" 
                Text='<%# DataBinder.Eval(Container.DataItem, "Project_Name") %>'></asp:Label>                                                                     
        </div>
        <div class="contentParent" id="STcontent" runat="server">                                                                  
            <asp:UpdatePanel ID="UpdatePanelST" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">                                                  
                <ContentTemplate>                                                                   
                    <cc1:AsyncFileUpload ID="STAsyncFileUpload_Pdf" runat="server" Width="500px" 
                    CompleteBackColor="White" OnClientUploadError="STuploadError" OnClientUploadComplete="STuploadComplete"                                                                                                                            
                    OnClientUploadStarted="STUploadedStartedPdfFile" UploadingBackColor="#CCDDEE"                                                                                                                            
                    UploaderStyle="Modern" ThrobberID="STinProgress" 
                    OnUploadedComplete="STPdf_FileUploadComplete" />                                                                           
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    </ItemTemplate> 
</asp:repeater>

My itemdatabound:

public void rptCore_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    //load controls data and calculations here.. like fileupload control etc
}

According to your requirement use for/Foreach loop by calling table/div structure in place of repeater..

For your logic call 10 records from last index and add in your table/div .

This will solve your problem and it is very effective without making any performance issue..

For eg. follow below logic -

DataTable dt = GetYourRows(); 
String html = "";
foreach(DataRow dr in dt.Rows)
{
 html += "<div>"+dr["column"].ToString();+"</div>";
}

then use your html anywhere in your existing HTML code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM