Based on the code you would encounter the error at least in a situation where you don't have three rows selected in your gridview. In the code
Sql ="Insert into CO_PACKAGE_DETAIL values('" + dt1.Rows[0]["cpm_pkg_id"].ToString() + "','" + gvmajormaster.selectedrow(1].tostring.trim() + "','" + gvmajormaster.selectedrows[2].tostring().trim() + "')";
you refer to indexes 1 and 2. As the indexing starts from 0 these would be the second and the third selected rows. The same potential problem happens if dt1 contains no rows.
Because of this, before doing anything else in the code, check that correct amount of data is selected and present and inform the user if not.
Another note is that you should never concatenate values directly to the SQL statement. Instead, use parameters. Have a look at the examples in
SqlParameterCollection.AddWithValue Method[
^]