A
ashwin
I have a Data Grid to display employee names and codes. On clicking a
button (outside the datagrid) I perform some calculations which sets
the fields of other columns in the datagrid.
The problem I am facing is that not all columns are filled with values
resulting from the calculations. Only the first few rows are being
filled with results.
---------------------------------------------------------------------------------------------------------------------------------------------
The datagrid code follows :
<asp:datagrid id="dg1" runat="server" Width="920px" Height="145px"
PageSize="5" AutoGenerateColumns="False"
BorderStyle="Groove">
<ItemStyle ForeColor="Black"
BackColor="#B0C4DE"></ItemStyle>
<HeaderStyle Font-
Size="Smaller" Font-Names="Arial" Font-
Bold="True" HorizontalAlign="Center"
ForeColor="#FAFAD2"
BackColor="#4682B4"></HeaderStyle>
<Columns>
<asp:TemplateColumn
HeaderText="Employee Id">
<ItemStyle
ForeColor="Black"></ItemStyle>
<ItemTemplate>
<asp:Label ID="ecode" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"EmpIdCode") %>'>
</
asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Employee Name">
<ItemStyle
ForeColor="Black"></ItemStyle>
<ItemTemplate>
<asp:Label ID="ename" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"name") %>'>
</
asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Worked Days">
<ItemStyle
HorizontalAlign="Center" ForeColor="Black"></
ItemStyle>
<ItemTemplate>
<asp:Label ID="workdays" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Off Days">
<ItemStyle
HorizontalAlign="Center" ForeColor="Black"></
ItemStyle>
<ItemTemplate>
<asp:Label ID="offdays" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Holidays Payable">
<ItemStyle
HorizontalAlign="Center" ForeColor="Black"></
ItemStyle>
<ItemTemplate>
<asp:Label ID="holiday" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Holiday ( Double_Salary)">
<ItemStyle
HorizontalAlign="Center" ForeColor="Black"></
ItemStyle>
<ItemTemplate>
<asp:Label ID="Holiday2" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Payable Leave Days">
<ItemStyle
HorizontalAlign="Center" ForeColor="Black"></
ItemStyle>
<ItemTemplate>
<asp:Label ID="Leave" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Total Pay Days">
<ItemStyle
HorizontalAlign="Center" ForeColor="Black"></
ItemStyle>
<ItemTemplate>
<asp:Label ID="Total" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle
Mode="NumericPages"></PagerStyle>
</asp:datagrid>
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
code to fill in the columns :
Private Sub btnCal_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCal.Click
On Error GoTo er
If txtDateFrom.Text = "" Or txtDateTo.Text = "" Then
Call MessageBox("Date are Blank")
Else
For Each ditem In dg1.Items
empcode = ditem.FindControl("ecode")
wdays = ditem.FindControl("workdays")
off = ditem.FindControl("offdays")
hol = ditem.FindControl("holiday")
hol2 = ditem.FindControl("Holiday2")
leav = ditem.FindControl("Leave")
wdays.Text =
working_days(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"), empcode.Text)
off.Text =
off_days(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"))
hol.Text =
holiday(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd")) -
(hol_with_1_sal(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"), empcode.Text) +
hol_with_2_sal(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"), empcode.Text))
hol2.Text =
hol_with_2_sal(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"), empcode.Text)
leav.Text =
Leave_count(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"), empcode.Text,
Session("AccCompID"), Session("AccBranchID")) -
hol_leav(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"), empcode.Text,
Session("AccCompID"), Session("AccBranchID"))
Next
End If
Exit Sub
er:
Err.Clear()
Exit Sub
End Sub
button (outside the datagrid) I perform some calculations which sets
the fields of other columns in the datagrid.
The problem I am facing is that not all columns are filled with values
resulting from the calculations. Only the first few rows are being
filled with results.
---------------------------------------------------------------------------------------------------------------------------------------------
The datagrid code follows :
<asp:datagrid id="dg1" runat="server" Width="920px" Height="145px"
PageSize="5" AutoGenerateColumns="False"
BorderStyle="Groove">
<ItemStyle ForeColor="Black"
BackColor="#B0C4DE"></ItemStyle>
<HeaderStyle Font-
Size="Smaller" Font-Names="Arial" Font-
Bold="True" HorizontalAlign="Center"
ForeColor="#FAFAD2"
BackColor="#4682B4"></HeaderStyle>
<Columns>
<asp:TemplateColumn
HeaderText="Employee Id">
<ItemStyle
ForeColor="Black"></ItemStyle>
<ItemTemplate>
<asp:Label ID="ecode" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"EmpIdCode") %>'>
</
asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Employee Name">
<ItemStyle
ForeColor="Black"></ItemStyle>
<ItemTemplate>
<asp:Label ID="ename" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"name") %>'>
</
asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Worked Days">
<ItemStyle
HorizontalAlign="Center" ForeColor="Black"></
ItemStyle>
<ItemTemplate>
<asp:Label ID="workdays" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Off Days">
<ItemStyle
HorizontalAlign="Center" ForeColor="Black"></
ItemStyle>
<ItemTemplate>
<asp:Label ID="offdays" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Holidays Payable">
<ItemStyle
HorizontalAlign="Center" ForeColor="Black"></
ItemStyle>
<ItemTemplate>
<asp:Label ID="holiday" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Holiday ( Double_Salary)">
<ItemStyle
HorizontalAlign="Center" ForeColor="Black"></
ItemStyle>
<ItemTemplate>
<asp:Label ID="Holiday2" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Payable Leave Days">
<ItemStyle
HorizontalAlign="Center" ForeColor="Black"></
ItemStyle>
<ItemTemplate>
<asp:Label ID="Leave" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Total Pay Days">
<ItemStyle
HorizontalAlign="Center" ForeColor="Black"></
ItemStyle>
<ItemTemplate>
<asp:Label ID="Total" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server"></asp:TextBox>
</
EditItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle
Mode="NumericPages"></PagerStyle>
</asp:datagrid>
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
code to fill in the columns :
Private Sub btnCal_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCal.Click
On Error GoTo er
If txtDateFrom.Text = "" Or txtDateTo.Text = "" Then
Call MessageBox("Date are Blank")
Else
For Each ditem In dg1.Items
empcode = ditem.FindControl("ecode")
wdays = ditem.FindControl("workdays")
off = ditem.FindControl("offdays")
hol = ditem.FindControl("holiday")
hol2 = ditem.FindControl("Holiday2")
leav = ditem.FindControl("Leave")
wdays.Text =
working_days(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"), empcode.Text)
off.Text =
off_days(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"))
hol.Text =
holiday(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd")) -
(hol_with_1_sal(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"), empcode.Text) +
hol_with_2_sal(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"), empcode.Text))
hol2.Text =
hol_with_2_sal(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"), empcode.Text)
leav.Text =
Leave_count(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"), empcode.Text,
Session("AccCompID"), Session("AccBranchID")) -
hol_leav(Format(DateValue(txtDateFrom.Text), "yyyy-MM-dd"),
Format(DateValue(txtDateTo.Text), "yyyy-MM-dd"), empcode.Text,
Session("AccCompID"), Session("AccBranchID"))
Next
End If
Exit Sub
er:
Err.Clear()
Exit Sub
End Sub