Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 4th, 2008, 02:03 PM
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


Reply With Quote
  #2 (permalink)  
Old March 4th, 2008, 02:16 PM
Authorized User
 
Join Date: Jun 2006
Location: , , .
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,


Reply With Quote
  #3 (permalink)  
Old March 4th, 2008, 02:18 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:31 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.