Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 4th, 2008, 02:03 PM
Authorized User
 
Join Date: Jun 2006
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


 
Old March 4th, 2008, 02:16 PM
Authorized User
 
Join Date: Jun 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have listed the columns below:

<asp:TemplateField HeaderText="HoursPerUnit" SortExpression="HoursPerUnit">

<EditItemTemplate>

<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("HoursPerUnit") %>'></asp:TextBox>

</EditItemTemplate>

<ItemTemplate>

<asp:Label ID="Label7" runat="server" Text='<%# Bind("HoursPerUnit") %>'></asp:Label>

</ItemTemplate>

<FooterTemplate>

<asp:TextBox ID="NewHoursPerUnit" runat="server"></asp:TextBox>

</FooterTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="PeoplePerUnit" SortExpression="PeoplePerUnit">

<EditItemTemplate>

<asp:TextBox ID="Tbx7" runat="server" Text='<%# Bind("PeoplePerUnit") %>'></asp:TextBox>

</EditItemTemplate>

<ItemTemplate>

<asp:Label ID="Lbl7" runat="server" Text='<%# Bind("PeoplePerUnit") %>'></asp:Label>

</ItemTemplate>

<FooterTemplate>

<asp:TextBox ID="NewPeoplePerUnit" runat="server"></asp:TextBox>

</FooterTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="TotalHoursPerUnit" SortExpression="TotalHoursPerUnit">

<EditItemTemplate>

<asp:TextBox ID="Tbx8" runat="server" Text='<%# Bind("TotalHoursPerUnit") %>'></asp:TextBox>

</EditItemTemplate>

<ItemTemplate>

<asp:Label ID="Lbl8" runat="server" Text='<%# Bind("TotalHoursPerUnit") %>'></asp:Label>

</ItemTemplate>

<FooterTemplate>

<asp:TextBox ID="NewTotalHoursPerUnit" runat="server"></asp:TextBox>

</FooterTemplate>

</asp:TemplateField>



Thank you,


 
Old March 4th, 2008, 02:18 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Not sure how this is an ASP.NET problem.

You probably need to adjust your javascript to be something like

TotalHoursPerUnit.value = (parseInt(HoursPerUnit.value) * parseInt(PeoplePerUnit.value))

or something similar.


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to cast object of type 'TheBeerHouseSection DyerOppenheimer BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 June 10th, 2008 12:13 PM
Unable to cast object of type galua SQL Language 3 January 9th, 2008 01:31 PM
Error Type unable to solve hayley Classic ASP Databases 4 January 25th, 2005 05:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.