0

このページには、ラジオ ボタンの 2 つの項目リストが含まれています。項目リストの値に「同意する」を選択した場合、テキスト ボックスの検証は必要ありません。別の値の場合は、「拒否」の検証が必要です (テキスト ボックスを埋めるため)

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        AllowPaging="True" DataSourceID="SqlDataSource1" 
         OnRowCommand="GridView1_RowCommand" 
        onselectedindexchanged="GridView1_SelectedIndexChanged">
         <Columns>

         <asp:BoundField DataField="GradeID" HeaderText="GradeID"  SortExpression="GradeID" />
                   <asp:BoundField DataField="Diagnosis" HeaderText="Diagnosis" SortExpression="Diagnosis" />

                     <asp:BoundField DataField="MileStoneID" HeaderText="MileStoneID" SortExpression="MileStoneID" />

<asp:TemplateField  HeaderText="Feedback">
                <ItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server"  ></asp:TextBox>


                </ItemTemplate>
                </asp:TemplateField>


                                   <asp:TemplateField HeaderText="select one">
                     <ItemTemplate>
                           <asp:RadioButtonList ID="Rd1" runat="server" RepeatDirection="Horizontal"  AutoPostBack="true" CausesValidation="false" DataTextField='<%DataBinder.Eval(Container.DataItem,"Feedback")%>'  EnableViewState="false"   >
                             <asp:ListItem Text="Accept" Value="1"  ></asp:ListItem>
                             <asp:ListItem Text="Reject" Value="2"  ></asp:ListItem>
                                                      </asp:RadioButtonList>
                             </ItemTemplate>
                             </asp:TemplateField>
                                 <asp:TemplateField HeaderText="select one">
                     <ItemTemplate>
                         <asp:TextBox ID="TextBox1" runat="server"  Visible="false"></asp:TextBox>
                         </ItemTemplate>
                         </asp:TemplateField>


                   <asp:TemplateField HeaderText="submit">
                     <ItemTemplate>
    <asp:Button ID="Button1" runat="server" Text="Button" CommandName="select"EnableViewState="false" 
        />
        </ItemTemplate>
        </asp:TemplateField>
        </Columns>
                </asp:GridView>

aspx.cs ページで

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

     }
4

1 に答える 1