Click here to Skip to main content
15,906,097 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I am trying to carryout database update, i want to be able to retrieve record from datagrid based on checkbox value(s) and update the database with it using button click event.

i have tried this:

C#
if ( e.RowIndex < 0 || e.ColumnIndex < 0 )
            {
                return;
            }

            string deviceType = "", deviceName = "", modelNumber = "", macAddress = "";
            string  isActive, isInUse;
            int deviceId=0;
            deviceId = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value + "");
           
                   
                    deviceType = dataGridView1.Rows[e.RowIndex].Cells[1].Value + "";
                    deviceName = dataGridView1.Rows[e.RowIndex].Cells[2].Value + "";
                    modelNumber = dataGridView1.Rows[e.RowIndex].Cells[3].Value + "";
                    macAddress = dataGridView1.Rows[e.RowIndex].Cells[4].Value + "";
                    isActive = dataGridView1.Rows[e.RowIndex].Cells[5].Value + "";
                    isInUse = dataGridView1.Rows[e.RowIndex].Cells[6].Value + "";


This seem to work only on a cellclick event, please how do i achieve this in a button click event
Posted
Comments
[no name] 11-Aug-14 14:07pm    
Create a button click handler
Loop through the rows in your grid
Pick out the rows that the checkbox is checked
If checked update your database

1 solution

Dear mfon peter,

I suggesting you go through this article wil help you.


http://aspsnippets.com/Articles/Bulk-Edit-Update-Multiple-Rows-in-ASPNet-GridView-using-CheckBoxes.aspx[^]



Edit Individual GridView Cells in ASP.NET[^]


http://aspadvice.com/blogs/azamsharp/archive/2006/12/18/GridView-Update-All-Rows-At-Once.aspx[^]



Sufficient to solve your problem, If not, please, revert back with deailed codes.

Thank You.
Manoj Kalla
 
Share this answer
 
Comments
Uwakpeter 14-Aug-14 6:02am    
I am working on C# Windows Application but not web. Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900