Although the asp.net datagrid is well known as a very good form control, but it is not flattering to mention the editing of the DataGrid, there is a big problem with the data submission function of the DataGrid: in the DataGrid, Each edit row is to submit a row, that is, "one-line edit, one-line submission," so that if the number of rows edited, not only the user's cumbersome operation, but also caused frequent access to the server, greatly reducing system efficiency.
Of course, there's a reincarnated solution, which is to move the edited content to another page and edit it in the TextBox. However, think carefully, this method is not to deceive themselves, and in the grid when we edit the total can not always use the TAB key to achieve grid (TEXTBOX) between the jump bar, if the response to return events, then need programmers waste a lot of energy to develop.
How to solve the above problems? Below I recommend a I am using the domestic datagrid:smartgrid (Sky Software station can download: http://www.skycn.com/soft/23547.html), this control I have spent a good long time, Now let's explore the SmartGrid of multiple-line submissions: SmartGrid does not have those button columns in the DataGrid but the entire form has only one submit button, whether you change a row or multiple lines can be a one-time submission, here are some examples:
Example:
The illustration above is a good example of editing, and the example shows that you can edit multiple lines or edit a line and then submit together.
Code:
to modify the code for a button:
private void Btonsave_click (object sender, System.EventArgs e)
{
This . Datagrid1.readonly = false;//into edit
This . Datagrid1.allowadd = true;//Allow adding
This . Datagrid1.allowdelete = true;//Allow deletion
}
This code is a unique property of SmartGrid you can set up a variety of functions to add and remove edits
To save the button's code:
private void Button2_Click (object sender, System.EventArgs e)
{
datatable t = (DataTable) this. Smartgrid1.datasource;
this.sqlDataAdapter1.Update (t);
t.clear ();
This.sqlDataAdapter1.Fill (t);
This . Smartgrid1.datasource = t;
}
This is the whole of the data submitted to the database, which is suitable for large amounts of data
There is also a data-by-row submission to the server
Code:
private void Btonsave_click (object sender, System.EventArgs e)
{
DataTable tb= (DataTable) this. Smartgrid1.datasource;
sqlparameter[] parameters=new sqlparameter[5];
foreach (DataRow Dr in TB.) Rows)
{
parameters[0]=new SqlParameter ("@customerId", "" +dr[1]+ ");
parameters[1]=new SqlParameter ("@companyName", "" +dr[0]+ ");
parameters[2]=new SqlParameter ("@contactName", "" +dr[2]+ ");
parameters[3]=new SqlParameter ("@contactTitle", "" +dr[3]+ ");
parameters[4]=new SqlParameter ("@address", "" +dr[4]+ ");
//EAMPD is the class execute is the function that executes the stored procedure parameters is the parameter required by the stored procedure
Eampd.execute ("Creatlayer", parameters);
}
}