2015-09-27 3 views
0

Я делаю веб-приложение для экзамена в ASP.NET. Я использую grid-view для отображения вопроса и возможных ответов. Я задал размер сетки - 1, поэтому он отображает только один вопрос на индекс страницы. Я использую переключатель для выбора нескольких вариантов.переключатель в поле шаблона сетки

Когда я выбираю радиокнопку и перехожу к следующему типу или следующей странице индекса сетки и снова возвращаю предыдущий вопрос, тогда я вижу, что переключатель, который я выбрал ранее, не выбран. Что я должен сделать для этого?

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
 
         AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1" 
 
         GridLines="None" Height="380px" 
 
         onpageindexchanging="GridView1_PageIndexChanging" 
 
         onprerender="GridView1_PreRender" onrowcommand="GridView1_RowCommand" 
 
         OnRowDataBound="GridView1_RowDataBound" 
 
         onselectedindexchanged="GridView1_SelectedIndexChanged" PageSize="1" 
 
         ShowHeader="False" style="margin-right: 0px; margin-bottom: 0px;" 
 
         Width="100%"> 
 
         <Columns> 
 
          <asp:TemplateField> 
 
           <ItemTemplate> 
 
            <table style=" width:100%; height: 550px;"> 
 
             <tr> 
 
              <td class="style6" colspan="2" colspan="3" 
 
               
 
               style="border-width: 1px; border-bottom-style: inset;"> 
 
               <asp:Label ID="Label14" runat="server" Font-Size="Large" Text="Question No :-"></asp:Label> 
 
               <asp:Label ID="Label4" runat="server" Font-Bold="True" Font-Size="Large" 
 
                Text='<%# Eval("id") %>'></asp:Label> 
 
              </td> 
 
             </tr> 
 
             <tr> 
 
              <td class="style4" colspan="2" colspan="2"> 
 
               <asp:Label ID="Label15" runat="server" Font-Bold="True" Text="Question:-" 
 
                Font-Size="Large"></asp:Label> 
 
               &nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp; <asp:Label ID="Label6" runat="server" Font-Bold="False" 
 
                Text='<%# Eval("Question") %>'></asp:Label> 
 
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 
              </td> 
 
             </tr> 
 
             <tr> 
 
              <td class="style9" style=" padding-top:10px"> 
 
               A:-<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True" 
 
                Font-Bold="False" 
 
                oncheckedchanged="RadioButton1_CheckedChanged" Text='<%# Eval("A") %>' /> 
 
               <br /> 
 
              </td> 
 
              <td class="style1" rowspan="4" style=" padding-top:10px"> 
 
               <asp:Image ID="Image1" runat="server" BorderStyle="None" Height="149px" 
 
                ImageUrl='<%# Eval("image") %>' Width="449px" /> 
 
              </td> 
 
             </tr> 
 
             <tr> 
 
              <td class="style9"> 
 
               B:-<asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True" 
 
                Font-Bold="False" 
 
                oncheckedchanged="RadioButton2_CheckedChanged" Text='<%# Eval("B") %>' /> 
 
               <br /> 
 
              </td> 
 
             </tr> 
 
             <tr> 
 
              <td class="style9"> 
 
               C:-<asp:RadioButton ID="RadioButton3" runat="server" AutoPostBack="True" 
 
                Font-Bold="False" 
 
                oncheckedchanged="RadioButton3_CheckedChanged" Text='<%# Eval("C") %>' /> 
 
               <br /> 
 
              </td> 
 
             </tr> 
 
             <tr> 
 
              <td class="style9"> 
 
               D:-<asp:RadioButton ID="RadioButton4" runat="server" AutoPostBack="True" 
 
                Font-Bold="False" 
 
                oncheckedchanged="RadioButton4_CheckedChanged" Text='<%# Eval("D") %>' /> 
 
               <br /> 
 
              </td> 
 
             </tr> 
 
             <tr> 
 
              <td colspan="2"> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <asp:Button ID="Button12" runat="server" BackColor="#006699" BorderStyle="None" 
 
                Font-Bold="True" Font-Size="Large" ForeColor="White" Height="34px" 
 
                Text="Next&gt;&gt;&gt;" Width="230px" /> 
 
               &nbsp;<asp:Button ID="Button2" runat="server" BackColor="#006699" BorderStyle="None" 
 
                CommandArgument='<%# Eval("id") %>' CommandName="Next" Font-Bold="True" 
 
                Font-Size="Large" ForeColor="White" Height="34px" Text="Mark for Review &amp; Next" 
 
                Width="229px" /> 
 
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 
               <asp:Button ID="Button1" runat="server" BackColor="#006699" BorderStyle="None" 
 
                CommandArgument='<%# Eval("id") %>' CommandName="Save" Font-Bold="True" 
 
                Font-Size="Large" ForeColor="White" Height="34px" OnClick="Button1_Click" 
 
                Text="Save and Next" Width="230px" /> 
 
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 
              </td> 
 
             </tr> 
 
            </table> 
 
           </ItemTemplate> 
 
           <AlternatingItemTemplate> 
 
            <table style=" width:100%; height: 550px;"> 
 
             <tr> 
 
              <td class="style9" colspan="2"> 
 
               Q<span ID="GridView1_ctl02_Label14" style="font-size:Large;">0</span> . 
 
               <span ID="GridView1_ctl02_Label6" style="font-size:Large;font-weight:bold;">abc</span> 
 
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 
              </td> 
 
             </tr> 
 
             <tr> 
 
              <td class="style9"> 
 
               &nbsp;&nbsp; C:-<span style="font-size:Large;font-weight:normal;"><input 
 
                ID="GridView1_ctl02_RadioButton3" name="GridView1$ctl02$RadioButton3" 
 
                onclick="javascript:setTimeout('__doPostBack(\'GridView1$ctl02$RadioButton3\',\'\')', 0)" 
 
                type="radio" value="RadioButton3" /><label 
 
                for="GridView1_ctl02_RadioButton3">abc</label></span> 
 
               <br /> 
 
              </td> 
 
              <td class="style6" colspan="2" 
 
               style=" border-width: 1px; border-bottom-style: inset;"> 
 
               &nbsp;&nbsp; A:-<span style="font-size:Large;font-weight:bold;" 
 
                ID="GridView1_ctl02_Label4"><input 
 
                ID="GridView1_ctl02_RadioButton1" name="GridView1$ctl02$RadioButton1" 
 
                onclick="javascript:setTimeout('__doPostBack(\'GridView1$ctl02$RadioButton1\',\'\')', 0)" 
 
                type="radio" value="RadioButton1" /><label 
 
                for="GridView1_ctl02_RadioButton1">abc</label></span> 
 
               <br /> 
 
              </td> 
 
              <td class="style1" rowspan="4" style=" padding-top:10px"> 
 
               <img ID="GridView1_ctl02_Image1" Src="" 
 
                style="border-style:None;height:98px;width:231px;border-width:0px;" /> 
 
              </td> 
 
             </tr> 
 
             <tr> 
 
              <td class="style4" colspan="2"> 
 
               &nbsp;&nbsp; B:-<span style="font-weight:bold;" ID="GridView1_ctl02_Label15"><input 
 
                ID="GridView1_ctl02_RadioButton2" name="GridView1$ctl02$RadioButton2" 
 
                onclick="javascript:setTimeout('__doPostBack(\'GridView1$ctl02$RadioButton2\',\'\')', 0)" 
 
                type="radio" value="RadioButton2" /><label 
 
                for="GridView1_ctl02_RadioButton2">abc</label></span> 
 
               <br /> 
 
              </td> 
 
             </tr> 
 
             <tr> 
 
             </tr> 
 
             <tr> 
 
              <td class="style9"> 
 
               &nbsp;&nbsp; D:-<span style="font-size:Large;font-weight:normal;"><input 
 
                ID="GridView1_ctl02_RadioButton3" name="GridView1$ctl02$RadioButton3" 
 
                onclick="javascript:setTimeout('__doPostBack(\'GridView1$ctl02$RadioButton3\',\'\')', 0)" 
 
                type="radio" value="RadioButton3" /><label 
 
                for="GridView1_ctl02_RadioButton4">abc</label></span> 
 
               <br /> 
 
              </td> 
 
             </tr> 
 
             <tr> 
 
              <td colspan="2"> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <br /> 
 
               <input ID="GridView1_ctl02_Button12" name="GridView1$ctl02$Button12" 
 
                style="color:White;background-color:#006699;border-style:None;font-size:Large;font-weight:bold;height:34px;width:230px;" 
 
                type="submit" value="&lt;&lt;&lt;Prv" /> &nbsp;<input 
 
                ID="GridView1_ctl02_Button2" name="GridView1$ctl02$Button2" 
 
                style="color:White;background-color:#006699;border-style:None;font-size:Large;font-weight:bold;height:34px;width:229px;" 
 
                type="submit" value="Mark and Next" /> 
 
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
 
               <input ID="GridView1_ctl02_Button1" name="GridView1$ctl02$Button1" 
 
                style="color:White;background-color:#006699;border-style:None;font-size:Large;font-weight:bold;height:34px;width:230px;" 
 
                type="submit" value="Save and Next" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
 
              </td> 
 
             </tr> 
 
            </table> 
 
           </AlternatingItemTemplate> 
 
          </asp:TemplateField> 
 
         </Columns> 
 
         <PagerStyle BackColor="White" BorderColor="White" ForeColor="White" /> 
 
        </asp:GridView>

ответ

0

Сохранить Ответ на View-состояния с помощью кода если (e.CommandName == "Сохранить") { Еогеасп (GridViewRow строки в GridView1.Rows) {

  if (((RadioButton)row.FindControl("RadioButton1")).Checked) 
      { 


       Label12.Text = "A"; 

      } 
      if (((RadioButton)row.FindControl("RadioButton2")).Checked) 
      { 


       Label12.Text = "B"; 

      } 

      if (((RadioButton)row.FindControl("RadioButton3")).Checked) 
      { 


       Label12.Text = "C"; 




      } 
      if (((RadioButton)row.FindControl("RadioButton4")).Checked) 
      { 


       Label12.Text = "D"; 

      } 

string m = Convert.ToString (e.CommandArgument);

  ViewState[m] = Label12.Text; 

}

Выполнить цикл в строке данных Bound событие GridView1 защищен недействительным GridView1_RowDataBound (объект отправителя, GridViewRowEventArgs е) {

if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     string id = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "id")); 


     int i, j; 
     for (i = 1; i <= 65; i++) 
     { 

      j = i + 100; 
      string k = i.ToString(); 
      string l = j.ToString(); 

      if (ViewState[l] != null) 
      { 

       if (id == k) 
       { 


        if (ViewState[l].ToString() == "A") 
        { 


         (e.Row.Cells[0].FindControl("RadioButton1") as RadioButton).Checked = true; 
        } 
        if (ViewState[l].ToString() == "B") 
        { 


         (e.Row.Cells[0].FindControl("RadioButton2") as RadioButton).Checked = true; 
        } 

        if (ViewState[l].ToString() == "C") 
        { 


         (e.Row.Cells[0].FindControl("RadioButton3") as RadioButton).Checked = true; 
        } 
        if (ViewState[l].ToString() == "D") 
        { 


         (e.Row.Cells[0].FindControl("RadioButton4") as RadioButton).Checked = true; 
        } 


       } 

      } 
     } 


    } 
} 

Решить !!!!!

Смежные вопросы