Hi,
use Hidden Field,i too faced the same problem some days back, i used Hidden Field and my problem solved.
Plz See the below Code, you will get an idea...
<asp:GridView runat="server" ID="gv1" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
Q No.<asp:Label runat="server" ID="lblqno" Text='<%#Eval("qno") %>'></asp:Label>
<asp:Label runat="server" ID="lblque" Text='<%#Eval("que") %>'></asp:Label><br />
a. <asp:RadioButton ID="rbt1" runat="server" Text='<%#Eval("ans1") %>' GroupName="q1"/>    
b. <asp:RadioButton ID="rbt2" runat="server" Text='<%#Eval("ans2") %>' GroupName="q1"/><br />
c. <asp:RadioButton ID="rbt3" runat="server" Text='<%#Eval("ans3") %>' GroupName="q1" />    
d. <asp:RadioButton ID="rbt4" runat="server" Text='<%#Eval("ans4") %>' GroupName="q1"/><br />
<asp:HiddenField runat="server" ID="hdfqno" Value='<%#Eval("qno") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Mu .CS File....
protected void btnSubmit_Click(object sender, EventArgs e)
{
foreach (GridViewRow grow in gv1.Rows)
{
RadioButton r1 = (RadioButton)grow.FindControl("rbt1");
RadioButton r2 = (RadioButton)grow.FindControl("rbt2");
RadioButton r3 = (RadioButton)grow.FindControl("rbt3");
RadioButton r4 = (RadioButton)grow.FindControl("rbt4");
HiddenField hdf = (HiddenField)grow.FindControl("hdfqno");
if (r1.Checked == true)
{
arr1.Add(hdf.Value);
arr2.Add(r1.Text);
queattempted++;
}
if (r2.Checked == true)
{
arr1.Add(hdf.Value);
arr2.Add(r2.Text);
queattempted++;
}
if (r3.Checked == true)
{
arr1.Add(hdf.Value);
arr2.Add(r3.Text);
queattempted++;
}
if (r4.Checked == true)
{
arr1.Add(hdf.Value);
arr2.Add(r4.Text);
queattempted++;
}
if (r1.Checked == false && r2.Checked == false && r3.Checked == false && r4.Checked == false)
{
arr1.Add(hdf.Value);
arr2.Add("");
}
}
SqlDataAdapter da = new SqlDataAdapter("select qno,ans from q2", cnn);
da.Fill(ds, "t2");
ArrayList dbarr = new ArrayList();
DataSet dsqno = new DataSet();
dsqno= ConvertArrayListToDataSet(arr1);
DataSet dsque = new DataSet();
dsque = ConvertArrayListToDataSet(arr2);
for(int i=0;i<ds.Tables["t2"].Rows.Count;i++)
{
string s1 = ds.Tables["t2"].Rows[i].ItemArray[0].ToString();
string s2 = dsqno.Tables[0].Rows[i].ItemArray[0].ToString();
if(s1==s2)
{
string r1=dsque.Tables[0].Rows[i].ItemArray[0].ToString();
string r2=ds.Tables["t2"].Rows[i].ItemArray[1].ToString();
if ( r1==r2 )
{
totalmarks++;
}
}
}
avg = totalmarks*100 / 30;
Session["avg1"] = avg;
Session["qattempted"] = queattempted;
Session["Remaining"] = (30 - queattempted).ToString();
Session["totalmarks"] = totalmarks;
Session["Wrong"] = (queattempted - totalmarks).ToString();
string s11; string s22;
s11 = (30 - minutes).ToString();
s22 = (59 - seconds).ToString(); ;
string s33 = s11+" : "+ s22;
Session["TimeTaken"] = s33;
Response.Redirect("ThankYou.aspx");
}