View Single Post
 
Old March 4th, 2008, 02:03 PM
cesemj cesemj is offline
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default Receiving Error Msg:Unable to cast object of type

Goal: enter a number in two fields HoursPerUnit and PeoplePerUnit and the value for the third field, TotalHoursPerUnit will populate after the the number in the two fields have been caculated. Using the code below I receive the error message above. Please tell me what am I doing wrong? Do I need to cast the text as a literal? Please help?

Thank you in advance,

<%@ Page Language="VB" MasterPageFile="Default.master" AutoEventWireup="false" CodeFile="frmHR.aspx.vb" Inherits="frmHR" title="HR" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
    HR<br />
<script language =javascript type="text/javascript">
function Calculate(HoursPerUnit, PeoplePerUnit, TotalHoursPerUnit)
{
    TotalHoursPerUnit.value = HoursPerUnit.value * PeoplePerUnit.value;
}

</script>
    <br />
    <asp:LinkButton ID="CheckAll" runat="server">Check All</asp:LinkButton>
    <asp:LinkButton ID="UncheckAll" runat="server">Uncheck All</asp:LinkButton><br />
    &nbsp;<br />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="HRID"
        DataSourceID="SqlDataSource1" AllowSorting="True" ShowFooter="True" AllowPaging="True" EmptyDataText="There is not any data.">
        <Columns>



-----------------------------------------------------

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim HoursPerUnit As System.Web.UI.WebControls.TextBox

Dim PeoplePerUnit As System.Web.UI.WebControls.TextBox
Dim TotalHoursPerUnit As System.Web.UI.WebControls.TextBox

If e.Row.RowType = DataControlRowType.DataRow And e.Row.Cells(2).Controls.Count > 0 Then

HoursPerUnit = CType(e.Row.Cells(2).Controls(1), System.Web.UI.WebControls.TextBox)
PeoplePerUnit = CType(e.Row.Cells(3).Controls(1), System.Web.UI.WebControls.TextBox)

TotalHoursPerUnit = CType(e.Row.Cells(4).Controls(1), System.Web.UI.WebControls.TextBox)
HoursPerUnit.Attributes.Add("onchange", "Calculate(" + HoursPerUnit.ClientID + "," + PeoplePerUnit.ClientID + "," + TotalHoursPerUnit.ClientID + ")")

PeoplePerUnit.Attributes.Add("onchange", "Calculate(" + HoursPerUnit.ClientID + "," + PeoplePerUnit.ClientID + "," + TotalHoursPerUnit.ClientID + ")")
End If

End Sub