编辑:
var dropDownControls = $('#<%=GridView1.ClientID %> select option:selected');
var checkbox = $.......checkbox .....
for(index = 0; index < dropDownControls.length; index++)
{
if (checkbox.checked) //my code gets exaclty what checkbox i checked
{
if(dropDownControls[index].selectedIndex == 0)
{
flag = false;
break;
}
}
}
上面的代码有效
我在gridivew 外面有我的按钮,我正在尝试验证gridivew 内部的下拉列表。
<asp:Button ID="btn" runat="server" Text="Submit" OnClick="btn_Click" CausesValidation="true"/>
<asp:GridView ID="GVInputMapping" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
EnableModelValidation="True" onrowdatabound="GVInputMapping_RowDataBound">
<Columns>
<asp:BoundField DataField="Name" ControlStyle-Width="250px" HeaderText="Name" SortExpression="Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox id="checkbox1" runat="server"/>
<asp:DropDownList runat="server" ID="ddldetail">
<asp:ListItem Selected="True" Value="0">Select me</asp:ListItem>
<asp:ListItem Value="1">abc</asp:ListItem>
<asp:ListItem Value="2">GHt</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="requiredDDL" runat="server"
ControlToValidate="ddldetail" ErrorMessage="Please select" InitialValue="Select me" Display="Dynamic"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>