Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET ASP:NET
i have a grid view. and in this i have a check box (in each row).and a text box also.
now i want to insert data of text box and some column(for example 'product type') into my database on click of a button that is outside grid view....
how can i do this also tell me stored procedure way to do this....
 
give some suggetion friends...
Posted 21-Dec-12 8:13am
GDdixit531
Comments
khiladi786 at 22-Dec-12 9:16am
   
hello bro , problem is not that which link you refer me...i am asking about check box as i told detailed in my question.....and your link give no idea bout this...?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

The stored procedure for this could be:
CREATE PROCEDURE [ProcedureName] 
	-- Add the parameters for the stored procedure here
	@Parameter1 INT
AS
BEGIN
    SET NOCOUNT ON;
	
    BEGIN TRANSACTION
    	
	-- if row alredy exists in a table update it else insert new row
    IF EXISTS ( SELECT  *
                FROM    [TableName]
                WHERE   <conditions> )
        BEGIN
            UPDATE  [TableName]
            SET     [FieldName] = [Value]
            WHERE   <conditions>
        END
    ELSE 
        BEGIN
	    INSERT INTO <tablename> VALUES <............>
        END
        
        
	 IF @@ROWCOUNT = 0 
        BEGIN
            ROLLBACK TRANSACTION
        END
    ELSE 
        BEGIN
            COMMIT TRANSACTION
        END
END
 
And in Click Event of a button do this:
protected void btnSave_Click(object sender, EventArgs e)
        {
            SqlConnection conn = <your connectionstring="">;
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = conn;
 
            String sqlQuery = "";
 
            try
            {
               conn.Open();
 
               for (int i = 0; i < yourdgv.RowCount - 1; i++)
               {
                 sqlCommand.CommandText = "<yourprocedurename>";
                 sqlCommand.CommandType = CommandType.StoredProcedure;
                 sqlCommand .Parameters.AddWithValue("@parameter1", <value>);
 
                 sqlCommand.ExecuteNonQuery();
 
                 //Data insertion completed.
               }
            }
            catch (Exception)
            {
                // your exception..
            }
            finally
            {
                conn.Close();
            }
        }
 
...
Plz. Let me know if this helps.
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

use following code...
protected void btnSaveData_Click(object sender, EventArgs e)
{
    foreach (GridViewRow row in grvYourGrid.Rows)
    {
        CheckBox chk = (CheckBox)row.FindControl("YourCheckBoxID");
        if (chk.Checked)
        {
            string textInTextBox =((TextBox)row.FindControl("YourTextBoxID")).Text;
            //same like for other controls
            //perform your database operation here
        }
    }
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 532
1 Maciej Los 450
2 Sergey Alexandrovich Kryukov 421
3 CPallini 200
4 Peter Leow 190
0 Sergey Alexandrovich Kryukov 6,888
1 OriginalGriff 5,342
2 Peter Leow 3,962
3 Mika Wendelius 2,850
4 CHill60 2,748


Advertise | Privacy | Mobile
Web01 | 2.8.150224.1 | Last Updated 23 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100