This is my GridView SourceCode:-
<asp:GridView ID="GrdCarry" runat="server" AutoGenerateColumns="False" CssClass="GridViewDefault"
AllowPaging="True" ShowFooter="true" OnRowCreated="GrdCarry_RowCreated">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="ChkTypehead"
runat="server"
onclick="javascript:SelectAllCheckboxes(this);"
/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="ChkType"
runat="server"
/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="LblSl" runat="server"
Text="Sl
No"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="LblSlNo"
runat="server"
Text="<%# Container.DataItemIndex + 1 %>"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Employee
Name</HeaderTemplate>
<ItemTemplate>
<asp:HiddenField ID="hdnEmployeeID"
runat="server"
Value='<%#Eval("Employee_ID") %>' />
<asp:Label ID="lblEmpName"
runat="server"
Text='<%#Bind("NAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Balance
Days
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblBalanceDays"
runat="server"
Text='<%#Bind("Balance_Days") %>'></asp:Label>
<asp:HiddenField ID="hdnBalanceDays"
runat="server"
Value='<%#Bind("Balance_Days") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="LblleaveCFDays"
runat="server"
Text="Leave CF
Days"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="TxtleaveCFDays"
AutoPostBack="true"
runat="server"></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="hdnMaxCarryFrwd"
Value='<%#Eval("Max_Carry_Forward_Leaves") %>'
runat="server"
/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
This is my GridView Row created Event:-
protected void
GrdCarry_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int index = e.Row.RowIndex;
e.Row.Attributes.Add("OnChange",
"CheckValidData(" + index + ")");
}
}
This is my Javascript Function:-
<head runat="server">
<link href="../../css/hrms_test.css"
rel="stylesheet"
type="text/css"
/>
<script src="../../Scripts/jquery-1.7.1.js"
type="text/javascript"></script>
<script src="../../Scripts/jquery-1.7.1.min.js"
type="text/javascript"></script>
<script type="text/javascript">
function SelectAllCheckboxes(chk) {
$('#<%=GrdCarry.ClientID %>').find("input:checkbox").each(function
() {
if (this
!= chk) {
this.checked = chk.checked;
}
});
}
function CheckValidData(i) {
var MaxCarryCheck = $("#GrdCarry_TxtleaveCFDays_"
+ i + "").val();
var x = parseInt(MaxCarryCheck, 10);
var MaxCarryLeaveDays = $("#GrdCarry_hdnMaxCarryFrwd_"
+ i + "").val();
var y = parseInt(MaxCarryLeaveDays, 10);
var BalanceDays = $("#GrdCarry_hdnBalanceDays_"
+ i + "").val();
var z = parseInt(BalanceDays, 10);
if (x > z) {
alert('you are Exceeding Balance Days :'
+ BalanceDays);
$("#GrdCarry_TxtleaveCFDays_"
+ i + "").val('');
}
else if (x > y) {
alert('you can not Exceed Maximum Carry
Forward Days:' + MaxCarryLeaveDays);
$("#GrdCarry_TxtleaveCFDays_"
+ i + "").val('');
}
}
</script>
<title></title>
</head>
No comments:
Post a Comment
Please don't spam, spam comments is not allowed here.