Hi sthsyed,
I have a created a sample which full fill your requirement
HTML
<div>
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvOrders_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Add">
<ItemTemplate>
<asp:CheckBox ID="checkOrders" OnCheckedChanged="checkOrders_CheckedChanged" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Vin_Number" HeaderText="Vin_Number" />
<asp:BoundField DataField="ModelNo" HeaderText="ModelNo" />
<asp:BoundField DataField="ModelYear" HeaderText="ModelYear" />
<asp:BoundField DataField="Modelcode" HeaderText="Modelcode" />
<asp:BoundField DataField="color" HeaderText="color" />
<asp:BoundField DataField="Loaction" HeaderText="Loaction" />
<asp:BoundField DataField="Status" HeaderText="Status" />
<asp:BoundField DataField="purchase_Date" HeaderText="PurchaseDate" />
</Columns>
</asp:GridView>
</div>
<div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('[id*=gvOrders] [id*=checkOrders]').on('click', function () {
var checked = $(this).closest('tr').find($('[id*=checkOrders]'))[0].checked;
if (checked) {
if ($(this).closest('tr:not(:has(th))').prev().find('th').length == 0) {
if ($(this).closest('tr').prev().find($('[id*=checkOrders]'))[0].checked == false) {
alert('Please select previous row');
return false;
}
}
else {
$(this).closest('tr').find('[id*=checkOrders]').attr('checked');
}
}
else {
if ($('[id*=gvOrders] tr:not(:has(th))').length != $(this).closest('tr')[0].rowIndex) {
if ($(this).closest('tr').next().find($('[id*=checkOrders]'))[0].checked == true) {
alert('Please UnCheck below row');
return false;
}
}
}
});
});
</script>
</div>
C#
private string constr = ConfigurationManager.ConnectionStrings["ConString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.GetOrders();
}
}
private void GetOrders()
{
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Orders ORDER BY [AddCheck] DESC,[purchase_Date] DESC", con))
{
DataTable dt = new DataTable();
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
gvOrders.DataSource = dt;
gvOrders.DataBind();
}
}
}
}
ScreenShot
Hope this works for you.