此页面包含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
}
答案 0 :(得分:0)
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "select") //for selecting Button
{
GridViewRow row = (GridViewRow)(((RadioButton)e.CommandSource).NamingContainer);
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, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
RadioButtonList Rd = (RadioButton) e.Row.FindControl("Rd1");
Rd.Items[1].Attributes.Add("OnClick", "return confirm('have you fill the feedback?')"); //for giving confirmation box when we click reject button
}
}