title: validation for radio button list in gridview in asp.net
body: <p>this page contains 2 itemlist for radio button,if i select itemlist  value "accept"then text box validation is not required, for another value "reject" validation is required (to fill the textbox)</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
          AllowPaging="True" DataSourceID="SqlDataSource1" 
           OnRowCommand="GridView1_RowCommand" 
          onselectedindexchanged="GridView1_SelectedIndexChanged"&gt;
           &lt;Columns&gt;
  
           &lt;asp:BoundField DataField="GradeID" HeaderText="GradeID"  SortExpression="GradeID" /&gt;
                     &lt;asp:BoundField DataField="Diagnosis" HeaderText="Diagnosis" SortExpression="Diagnosis" /&gt;
  
                       &lt;asp:BoundField DataField="MileStoneID" HeaderText="MileStoneID" SortExpression="MileStoneID" /&gt;
  
  &lt;asp:TemplateField  HeaderText="Feedback"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:TextBox ID="TextBox1" runat="server"  &gt;&lt;/asp:TextBox&gt;
  
  
                  &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
  
                                     &lt;asp:TemplateField HeaderText="select one"&gt;
                       &lt;ItemTemplate&gt;
                             &lt;asp:RadioButtonList ID="Rd1" runat="server" RepeatDirection="Horizontal"  AutoPostBack="true" CausesValidation="false" DataTextField='&lt;%DataBinder.Eval(Container.DataItem,"Feedback")%&gt;'  EnableViewState="false"   &gt;
                               &lt;asp:ListItem Text="Accept" Value="1"  &gt;&lt;/asp:ListItem&gt;
                               &lt;asp:ListItem Text="Reject" Value="2"  &gt;&lt;/asp:ListItem&gt;
                                                        &lt;/asp:RadioButtonList&gt;
                               &lt;/ItemTemplate&gt;
                               &lt;/asp:TemplateField&gt;
                                   &lt;asp:TemplateField HeaderText="select one"&gt;
                       &lt;ItemTemplate&gt;
                           &lt;asp:TextBox ID="TextBox1" runat="server"  Visible="false"&gt;&lt;/asp:TextBox&gt;
                           &lt;/ItemTemplate&gt;
                           &lt;/asp:TemplateField&gt;
  
  
                     &lt;asp:TemplateField HeaderText="submit"&gt;
                       &lt;ItemTemplate&gt;
      &lt;asp:Button ID="Button1" runat="server" Text="Button" CommandName="select"EnableViewState="false" 
          /&gt;
          &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;/Columns&gt;
                  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>in aspx.cs page </p>
  
  <pre><code>protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
  {
  
      foreach (GridViewRow row in GridView1.Rows)
      {
          if (e.CommandName == "select") //for selecting Button
          {
              RadioButtonList rbl = (RadioButtonList)row.FindControl("Rd1");//for selecting the particular radio button list
              if (rbl.SelectedValue == "1") //for selecting the radiobuttonlist option for accepting the data
              {
  //here it should ask for fill the textbox feedback
              }
              else
  
                  if (rbl.SelectedValue == "2") //for rejecting the data
                  {
                      //here validation is required to fill the textbox
                  }
  
          }
      }
  
  }
  
      protected void Rd1_DataBound(object sender, EventArgs e)
      {
  
       RadioButtonList Rd = (RadioButtonList)sender;
       Rd.Items[1].Attributes.Add("OnClick", "return confirm('have you fill the feedback?')"); //for giving confirmation box when we click reject button
  
       }
  </code></pre>