In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces ASP.NET how to achieve GridView to add a line of JS, the article is very detailed, has a certain reference value, interested friends must read it!
The effect is as follows
After clicking the add button
The JS file is as follows:
Foreground code:
Serial number, name, age, sex
Add a gridview control to store data in the background using DataTable. Headers and contents are used and displayed. This allows multiple controls in the column to meet the needs of the project.
Here is the JS code:
Var dgPersonsID = ""; $(document) .ready (function () {$("# dgPersons tr"). Eq (1). Hide (); function AddNewRow () {var tr = $("# dgPersons tr"). Eq (1). Clone (); tr.show (); tr.appendTo ("# dgPersons"); refreshNo (); return false } function refreshNo () {var dgg = document.getElementById (dgPersonsID); var index = 1; for (var I = 2; I < dgg.rows.length; + + I) {var cells = Dgg.rows [I] .cells; var row = dgg.rows [I] If (row.style.display! = "none") {cells [0] .firstChild.nodeValue = index++;}} return false;}
Mainly used to add a row in response to the add button, and refresh the data, here is mainly to refresh the serial number.
Background code
Method for reading data, specifically wrote a singleton mode of the class, I think this is good for management, all the code is written in the CS file of the page, not very convenient.
Public class MainManager {private DataTable personCollect = null; private static MainManager instance = null; public DataTable PersonCollect {get {return personCollect;} set {personCollect = value;}} public static MainManager DoGetInstance () {if (instance = = null) {instance = new MainManager () } return instance;} public void DoAddSinglePersons () {if (PersonCollect==null) {PersonCollect= new DataTable (); PersonCollect.Columns.Add ("p_id"); PersonCollect.Columns.Add ("p_name"); PersonCollect.Columns.Add ("p_age") PersonCollect.Columns.Add ("p_sex");} if (PersonCollect.Rows.Count < 1) {for (int I = 0; I < 1; iTunes +) {DataRow nrow = PersonCollect.NewRow (); nrow ["p_id"] = System.Guid.NewGuid (). ToString () Nrow ["p_name"] = "Northwest Poplar"; nrow ["p_age"] = 27; nrow ["p_sex"] = "male"; PersonCollect.Rows.Add (nrow);}}
The cs class of the page, which is responsible for loading data and binding.
Public partial class ChildFrm: System.Web.UI.Page {private MainManager dManager = null; protected void Page_Load (object sender, EventArgs e) {dManager = MainManager.DoGetInstance (); if (! IsPostBack) {if (dManager.PersonCollect! = null) {dManager.PersonCollect.Clear ();} dManager.DoAddSinglePersons () This.dgPersons.DataSource = dManager.PersonCollect; this.dgPersons.DataBind ();} above is all the content of the article "how to add a line of JS to GridView by ASP.NET". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.