On load it shows data perfect i want to check validation and show alert required quantity is greater then stock quantity
I suggest that you show the "alert" by changing a background-color of the row where required quantity is greater than stock quantity, as shown below:
Below is sample code which shows the above GridView.
Note that you have to modify the code if you want to show the "alert" only on button click. I believe that you will be able to do so easily.
.aspx.cs
Note that in the event handler for the GridView.RowDataBound event the required quantity and the stock quantity are compared and the background-color of the row is set to yellow if the required quantity is greater than the stock quantity.
using System;
using System.Data;
using System.Web.UI.WebControls;
namespace WebForms1
{
public partial class WebForm43 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = (DataRowView)e.Row.DataItem;
if ((Int16)drv["UnitsOnOrder"] > (Int16)drv["UnitsInStock"])
{
e.Row.CssClass = "style1";
}
}
}
}
}
.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm43.aspx.cs"
Inherits="WebForms1.WebForm43" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1 {
background-color:yellow;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:SqlDataSource ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:NORTHWINDConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice], [UnitsInStock], [UnitsOnOrder] FROM [Products]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataKeyNames="ProductID"
DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="ProductID"
HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName"
HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="UnitPrice"
HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="UnitsInStock"
HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
<asp:BoundField DataField="UnitsOnOrder"
HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder" />
</Columns>
</asp:GridView>
</form>
</body>
</html>
Above uses the Nortwind Products table: