DropDownList Validation not working inside Gridview

Posted by Sthsyed under ASP.NET on 10/19/2016 | Points: 10 | Views : 1239 | Status : [Member] | Replies : 0
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.


<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:CheckBox ID="chkHeader" runat="server" Checked="true" />
<asp:CheckBox ID="chkRow" runat="server" Checked="true" />
<asp:BoundField DataField="Vin" HeaderText="VinNumber" />
<asp:TemplateField HeaderText="Sales Person">
<asp:TextBox ID="txtSalesPersonName" runat="server" Text='<%# Eval("Sales_Person_Name") %>' />
<asp:DropDownList ID="ddlSalesPerson" runat="server" DataSourceID="SqlDataSource2"
DataTextField="SalesPersonName" DataValueField="SalesPersonName" AppendDataBoundItems="true">
<asp:ListItem Text="SELECT" Value="0" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:VehicleConnectionString %>"
SelectCommand="Select SPNID,SalesPersonName from R_ResrvSalesPerson">


<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;


(No response found.)

Login to post response