<asp:GridView ID="gvAttributes" runat="server"
AutoGenerateColumns="false" EnableModelValidation="True"
CssClass="GridViewStyle" onrowdatabound="gvAttributes_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="cbxAttributescheck" runat="server" Text=''
<%# Eval("AttributeName") %> AutoPostBack="true" OnCheckedChanged="cbxAttributescheck_CheckedChanged"/>
<asp:HiddenField ID="hdnAttributeValue" runat="server" Value=''
<%# Eval("AttributeID") %>' />
<asp:Label ID="lblDelete" runat="server" Text=''
<%# Eval("AttributeID") %>' Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Data Type" >
<ItemTemplate>
<asp:DropDownList ID="ddlAttributesDataType" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvAttributeType" runat="server"
ErrorMessage="*" Enabled="false"
ControlToValidate="ddlAttributesDataType" InitialValue="0">
</asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Allow Nulls" >
<ItemTemplate>
<asp:CheckBox ID="cbxAttributesisnull" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void cbxAttributescheck_CheckedChanged(object sender, EventArgs e)
{
CheckBox cbx = (CheckBox)sender;
string CurrentCbxId = ((CheckBox)sender).ClientID;
foreach (GridViewRow Row in gvAttributes.Rows)
{
if (((CheckBox)Row.FindControl("cbxAttributescheck")).ClientID.Equals(CurrentCbxId) && cbx.Checked)
{
RequiredFieldValidator rfvAttributeType = (RequiredFieldValidator)Row.FindControl("rfvAttributeType");
rfvAttributeType.Enabled = true;
}
}
}
我已经采用了上面的网格视图,我想在选中复选框时启用下拉所需的字段验证器。我想不通过 JavaScript 来做这个服务器端。我试过但无法解决。我尝试在选中复选框时启用验证器,否则它将被禁用。我需要这方面的帮助。