Asp.net implements data binding and paging using jQuery, asp. netjquery
Use jQuery to bind and pagination the data of server-side data display controls such as Gridview and Repeater. This article focuses on how to bind data.
Content
JQuery's strength and availability make it popular quickly. Microsoft also released a patch to allow VS to support intelligent sensing of jQuery. Due to the complexity of controls such as Gridview and Repeater, it is almost impossible to assign values to them on the client through javascript. However, we do not want to give up the powerful functions and convenience provided by these controls. In particular, we are used to using these controls to display a large amount of data. Therefore, it would be nice to combine jQuery and Gridview.
Recently, I prefer to use the Repeater control, so here I will use a Repeater to display the query results.
First, define the fields displayed by this control on the page:
<Asp: placeHolder ID = "specialRedeemPlaceHolder" runat = "server" Visible = "false"> <table id = "specialRedeemInfo"> <caption> query result </caption> <thead> <tr> <th> prize name </th> <th> beauty consultant No. </th> <th> quantity </th> <th> points required </th> <th> date </th> <th> Status </th> </tr> </thead> <tbody> <asp: repeater id = "rptSpecialRedeemInfo" runat = "server" EnableViewState = "false" onitemdatabound = "inline"> <ItemTemplate> <tr class = "item"> <td> <% # Eval ("PartName ") %> </td> <% # Eval ("ConsultantName") %> </td> <% # Eval ("ConsultantID ") %> </td> <% # Eval ("Quantity") %> </td> <% # Eval ("PointCost ") %> </td> <% # Eval ("InsertedTime") %> </td> <% # Eval ("DisplayStatus ") %> </td> <input id = "btnProcess" type = "button" runat = "server"/> </td> </tr> </ItemTemplate> </asp: repeater> </tbody> </table> </asp: PlaceHolder>
Because AJAX queries are implemented, you can set the repeaterEnableViewState="False". This placeholder defines the data display format, rather than the position displayed on the webpage. Therefore, you need to define a position to display the query results. A div is defined here.
<div id="queryResult"> </div>
OK. When the client processes the query event, you can use jQuery's load method:
$("#queryResult").load("SpecialRedeemManagement.aspx #specialRedeemInfo",
{Func: "Search", ConsultantID: consultantId}, // Parameters
AjaxComplete); // call this JS when the query is complete.
The server can obtain parameters through Request. Params ["Func. When processing this query event, first
SpecialRedeemPlaceHolder. Visible = true; // you can specify true for a placeholder.
Then bind the repeater with the data (the code is too simple ). (Onitemdatabound this event is still valid)
Then write the palcecontrol to the Response stream:
StringWriter tw = new StringWriter();
// *** Simple rendering - just write the control to the text writer// *** works well for single controls without containersHtml32TextWriter writer = new Html32TextWriter(tw);this.specialRedeemPlaceHolder.RenderControl(writer);writer.Close();Response.Write(tw.ToString());Response.End();
Explain this sentence: $ ("# queryResult"). load ("SpecialRedeemManagement. aspx # specialRedeemInfo ",
When "# specialRedeemInfo" is added, jQuery will only obtain the control with the returned Response id specialRedeemInfo. The advantage is that, if needed, multiple control streams can be returned for display in a query.
In addition, another thing that needs to be done is to rewrite a method:
public override void VerifyRenderingInServerForm(Control control){ //base.VerifyRenderingInServerForm(control);}
As for what this method does, please check it if you are interested.
How can I implement pagination when I bind table data to an HTML page in aspnet?
Write Stored Procedure
Count = number of entries displayed on one page num = total number of entries displayed on the page = total number of entries that meet the query requirements
Stored Procedure input parameters [count, num,] and output parameters [total]
Paging SQL statement:
Select top count * from table name where id not in (select top (num-1) * count) * from table name)
Should you write SQL statements for other stored procedures?
How does aspnet implement the following data binding?
I just counted 14 pieces of data on your page! I don't know if this is in a table! If you are in a table, you can do this!
First, check the number of data entries and divide it by 14 to get the page number.
And then begin binding! Of course, your query condition is like this: select top 14 * from table where Table id not in (your previous data <for example, if this is the second page, you will not in the first 14 IDs>) in this way, we can find the content on the second page!
When you return a 14-row dataset
First, put a Literal on your page.
After obtaining the dataset, we start to traverse this data source!
Then, we start to spell out the front-end code and finally output it to Literal!
A spelling example is like this!
StringBuilder sb = new StringBuilder ();
Sb. append ("<table> <tr> <td>" + dataset that you traverse );
Sb. append ("</td> </tr> </table> ");
Literal. text = sb. toString ()
Because you already have a static page! The corresponding page style is also available! Just join StringBuilder!
This will display it!
Of course it's just a suggestion!
Baidu Hi