Hello all
I have a grid view where i have drop down list,when i click button(btnReserve) it checks for all the drop down should be selected(not the default value any should be selected).
It is working fine, now i add check box inside the grid view and when i click button(btnReserve) only selected check box records should be check for drop down list select.
Hope you understand.
I have provided the code below.
<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:BoundField DataField="Model No_" HeaderText="Model No" />
<asp:BoundField DataField="Model Year" HeaderText="Model Year" />
<asp:BoundField DataField="Model Code" HeaderText="Model Code" />
<asp:BoundField DataField="Color" HeaderText="Color" />
<asp:BoundField DataField="Location" HeaderText="Location" />
<asp:BoundField DataField="Status" HeaderText="Status" />
<asp:TemplateField HeaderText="Sales Person">
<ItemTemplate>
<asp:TextBox ID="txtSalesPersonName" runat="server" Text='<%# Eval("Sales_Person_Name") %>' />
</ItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddlSalesPerson" CssClass="ddldp" 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:VehicleConnectionString1 %>"
SelectCommand="Select SPNID,SalesPersonName from R_ResrvSalesPerson"></asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Check_Remarks" HeaderText="Check Remarks" />
</Columns>
</asp:GridView>
<script src="Jquery/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("[id$=btnReserveTest]").click(function () {
var flag = 1;
$('.ddldp').each(function () {
if ($('#' + this.id).val() == 0) {
flag = 0;
}
});
if (flag != 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>