Hi all, I need your help.
I need set enabled equal to true the RequiredFieldValidator "rftxt" when at least one of the three DropDownLists contains KO value.
I don't have error but the RequiredFieldValidator "rftxt" remains disabled.
My code below
<asp:TemplateField
HeaderText="t1"
ItemStyle-CssClass="ddl_Class_new"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<div>
<asp:DropDownList ID="ddl1" runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="OnSelectedIndexChanged"
BackColor="Yellow"
CssClass="ddl_Class_new">
<asp:ListItem Text="[ === === === ]" Value=""></asp:ListItem>
<asp:ListItem Text="OK" Value="OK"></asp:ListItem>
<asp:ListItem Text="KO" Value="KO"></asp:ListItem>
</asp:DropDownList>
</div>
<br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField
HeaderText="t2"
ItemStyle-CssClass="ddl_Class_new"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<div>
<asp:DropDownList ID="ddl2" runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="OnSelectedIndexChanged"
BackColor="Yellow"
CssClass="ddl_Class_new">
<asp:ListItem Text="[ === === === ]" Value=""></asp:ListItem>
<asp:ListItem Text="OK" Value="OK"></asp:ListItem>
<asp:ListItem Text="KO" Value="KO"></asp:ListItem>
</asp:DropDownList>
</div>
<br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField
HeaderText="t3"
ItemStyle-CssClass="ddl_Class_new"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<div>
<asp:DropDownList ID="ddl3" runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="OnSelectedIndexChanged"
BackColor="Yellow"
CssClass="ddl_Class_new">
<asp:ListItem Text="[ === === === ]" Value=""></asp:ListItem>
<asp:ListItem Text="OK" Value="OK"></asp:ListItem>
<asp:ListItem Text="KO" Value="KO"></asp:ListItem>
</asp:DropDownList>
</div>
<br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField
HeaderText="Note"
ItemStyle-CssClass="ddl_Class_new"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<div>
<br />
<asp:TextBox ID="t_txt" runat="server"
CssClass="ddl_Class_new"
TextMode="MultiLine"
Enabled="true"></asp:TextBox>
<asp:RequiredFieldValidator ID="rftxt" runat="server"
ControlToValidate="t_txt"
Enabled="false"
SetFocusOnError="true"
ErrorMessage="Insert value"
Display="None"
ValidationGroup="Validation2"
CssClass="validation-summary-errors-one"></asp:RequiredFieldValidator>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:ImageButton ID="btn"
ImageUrl="/aspnet/img/btn.gif"
ValidationGroup="Validation2"
runat="server"
OnClick="btn_Click"
OnClientClick="return confirm('Are you sure?')"
CssClass="ddl_Class_new"
Visible="true" />
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
GridViewRow row = (GridViewRow)ddl.NamingContainer;
DropDownList t1 = (DropDownList)row.FindControl("ddl1");
DropDownList t2 = (DropDownList)row.FindControl("ddl2");
DropDownList t3 = (DropDownList)row.FindControl("ddl3");
TextBox t_txt = (TextBox)row.FindControl("txt");
RequiredFieldValidator t_rftxt = (RequiredFieldValidator)row.FindControl("rftxt");
string sp_t1 = t1.SelectedValue;
string sp_t2 = t2.SelectedValue;
string sp_t3 = t3.SelectedValue;
if (sp_t1.ToString() == "KO" || sp_t2.ToString() == "KO" || sp_t3.ToString() == "KO")
{
t_rftxt.Enabled = true;
}
else
{
// ...
}
}