I have a dropdownlist inside a gridview,the drop list should populate from database and default value should be SELECT.
when i Click Save button it should check all the dropdownlist values. If any one is still SELECT it should prompt error select any values.
When i normaly check without inside gridview it works fine and not inside gridview.
I have attached my codings below.
Help in this regard.
Thanks
<asp:GridView ID="GVResrv" runat="server" Width="100%" AutoGenerateColumns="false"
TabIndex="1" Font-Names="Times New Roman" Font-Size="Smaller" HeaderStyle-HorizontalAlign="Center">
<Columns>
<asp:CommandField ShowSelectButton="true" HeaderText="Details" SelectText="Details" />
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" runat="server" Checked="true" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server" Checked="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Vin" HeaderText="VinNumber" />
<asp:TemplateField HeaderText="Sales Person">
<ItemTemplate>
<asp:TextBox ID="txtSalesPersonName" runat="server" Text='<%# Eval("Sales_Person_Name") %>' />
</ItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddlSalesPerson" runat="server" DataSourceID="SqlDataSource2"
DataTextField="SalesPersonName" DataValueField="SalesPersonName" AppendDataBoundItems="true">
<asp:ListItem Text="SELECT" Value="0" />
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:VehicleConnectionString %>"
SelectCommand="Select SPNID,SalesPersonName from R_ResrvSalesPerson"></asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("[id$=btnSave]").click(function () {
if ($("[id$=ddlSalesPerson]").val() != 0) {
//Selected option from dropdownlist
return true;
} else {
//Not selected so alert user to select any option
alert('Please select Sales Person Name');
return false;
}
});
});
</script>