How to add automatic growth columns to DataGrid

zhaozj2021-02-16  59

9CBS - Document Center - .NET title How to add automatic growth column for DataGrid Cuike519 (original) keyword DataGrid; Automatic growth column

How to add automatic growth columns to DataGrid I think we all know how to add self-growth columns in the database, we can make this self-growth column to the DataGrid make the user convenient to know the first few lines, today I introduce a use The database can simply display the method of growing column, some people may say that since the database supports us? I think two reasons: 1, not all the tables have self-growth columns. 2. The phenomenon of breaking is displayed when the self-growth column does not automatically copy, even if replication is possible. But first, this method is that this method can only display the serial number of the current page, that is, if there is a paging it can only mark the serial number of the current page. If you want to achieve a pagination, I want to use the database to be simpler than this method, because if you still use this method, you will have a status, here I don't consider this method, but I will give a database in the end of the article. solution. Ok, the following is a topic, first we need to place a DataGrid on the page. We use the Northwind database example: The DataGrid of the HTML page is as follows: <% # container.itemindex 1%> Below we can write his background code CS The file has been added in its Page_Load Add a binding method as follows: private void page_load (object sender, system.eventargs e) {// Place user code here to initialize page strconnection = configurationSettings.Appsettings ["sa"] .ToString (); myConnection = new SqlConnection (strConnection); SqlDataAdapter myAdapter = new SqlDataAdapter ( "SELECT CategoryName, Description FROM Categories", myConnection); // ds is convenient for paging a global variable myAdapter.Fill (ds); this .grdtest.dataasource = ds.tables [0] .defaultview; this.grdtest.database ();} From the above process, you can see We use Table Categories so that we can produce a column of self-growth, which starts from 1.

What should I do if we want a column starting from 0? We can change the below in