Before we look at the problem you have noticed, let's deal with the really important problem. Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.
When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;
Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
DROP TABLE MyTable;
A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.
So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
And also the trivial-but-important one:
rollno1
never changes, and is a string so the "no" part of the name is misleading as it can't be treated as a number even if you do want to increment it somewhere - which you probably shouldn't...
No, when you have fixed those throughout your app - miss one place and your DB will vanish suddenly - you can look at the one you have noticed.
When you report an error, copy and paste it: get it right, or it makes it harder for people to help you. I'll assume you mean the error is "Argument Out Of Range Exception unhandled by user code".
What that means is that your code:
RadioButton rbtn1 = (RadioButton)GridView1.Rows[rnum].Cells[12].FindControl("rbtnpresent1");
is accessing an array (or other collection) with an index that is outside the valid range of values. If the collection contains 4 elements, then valid indexes are 0, 1, 2, and 3 only. Any negative values, or a value greater than 3 will give you this exception.
So I'd assume that either
rnum
or
12
is causing the problem.
Why? I don;t know, and I can't find out as I can't run your code with your data which is needed to work out the reason.
So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!