Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 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
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 24th, 2006, 11:36 AM
Registered User
Join Date: Apr 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Input string was not in a correct format.

Completely stumped. Any help would be greatly appreciated.

I'm getting the following error:

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

Line 288: txtEditFirstName = CType(e.Item.FindControl("txtEditFirstname"), TextBox)
Line 289: txtEditLastName = CType(e.Item.FindControl("txtEditLastname"), TextBox)
Line 290: intEditDeptID = CType(e.Item.Cells(5).FindControl("ddlEditDeptID") , DropDownList).SelectedValue
Line 291: chkEditUserAdmin = CType(e.Item.FindControl("chkEditAdmin"), CheckBox)
Line 292:

Source File: D:\WEBRoot\80.1\PMPrototype\admin\admin.aspx.vb Line: 290

Stack Trace:

[FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.Doubl eType.Parse(String Value, NumberFormatInfo NumberFormat) +195
Microsoft.VisualBasic.CompilerServices.Integ erType.FromString(String Value) +97

[InvalidCastException: Cast from string "" to type 'Integer' is not valid.]
Microsoft.VisualBasic.CompilerServices.Integ erType.FromString(String Value) +212
PMPrototype.pgAdmin.dgUsers_UpdateCommand(Ob ject sender, DataGridCommandEventArgs e) in D:\WEBRoot\80.1\PMPrototype\admin\admin.aspx.vb:29 0
System.Web.UI.WebControls.DataGrid.OnUpdateC ommand(DataGridCommandEventArgs e) +109
System.Web.UI.WebControls.DataGrid.OnBubbleE vent(Object source, EventArgs e) +507
System.Web.UI.Control.RaiseBubbleEvent(Objec t source, EventArgs args) +26
System.Web.UI.WebControls.DataGridItem.OnBub bleEvent(Object source, EventArgs e) +101
System.Web.UI.Control.RaiseBubbleEvent(Objec t source, EventArgs args) +26
System.Web.UI.WebControls.LinkButton.OnComma nd(CommandEventArgs e) +121
System.Web.UI.WebControls.LinkButton.System. Web.UI.IPostBackEventHandler.RaisePostBackEvent(St ring eventArgument) +116
System.Web.UI.Page.RaisePostBackEvent(IPostB ackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameVa lueCollection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1292

I do a view source on the code, and see that the value of the ddlEditDeptID cannot be "" because all of the list items (<option>) are numbers.

Here's the Code:

#Region " User Datagrid "

    Private Sub dgUsers_ItemDatabound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgUsers.ItemDataBound

        Select Case e.Item.ItemType

            Case ListItemType.EditItem, ListItemType.EditItem

                Dim ddlEditDept As DropDownList
                Dim lblDGDeptID As Label
                lblDGDeptID = CType(e.Item.Cells(4).FindControl("lblEditDeptID"), Label)
                ddlEditDept = CType(e.Item.Cells(5).FindControl("ddlEditDeptID"), System.Web.UI.WebControls.DropDownList)
                ddlEditDept = clsRBForm.MakeDDLDept(ddlEditDept, Integer.Parse(lblDGDeptID.Text))


        End Select

    End Sub

    Private Sub dgUsers_EditCommand(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs) Handles dgUsers.EditCommand

        dgUsers.EditItemIndex = e.Item.ItemIndex

    End Sub

    Private Sub dgUsers_CancelCommand(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs) Handles dgUsers.CancelCommand

        dgUsers.EditItemIndex = -1

    End Sub

    Private Sub dgUsers_UpdateCommand(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs) Handles dgUsers.UpdateCommand

        Dim txtEditUserName As TextBox
        Dim txtEditFirstName As TextBox
        Dim txtEditLastName As TextBox
        Dim ddlEditUserDept As DropDownList
        Dim intEditDeptID As Integer
        Dim chkEditUserAdmin As CheckBox
        Dim objUser As clsUser

        If IsValid() Then
            txtEditUserName = CType(e.Item.FindControl("txtEditUsername"), TextBox)
            txtEditFirstName = CType(e.Item.FindControl("txtEditFirstname"), TextBox)
            txtEditLastName = CType(e.Item.FindControl("txtEditLastname"), TextBox)
            intEditDeptID = CType(e.Item.Cells(5).FindControl("ddlEditDeptID"), DropDownList).SelectedValue
            chkEditUserAdmin = CType(e.Item.FindControl("chkEditAdmin"), CheckBox)

            objUser = New clsUser(CInt(dgUsers.DataKeys(e.Item.ItemIndex)))

            objUser.Username = txtEditUserName.Text
            objUser.Firstname = txtEditFirstName.Text
            objUser.Lastname = txtEditLastName.Text
            objUser.DeptID = intEditDeptID
            objUser.Admin = chkEditUserAdmin.Checked


            dgUsers.EditItemIndex = -1

            SetMessage("User updated.")
        End If

    End Sub

    Private Sub btnAddUser_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles btnAddUser.Click


    End Sub

#End Region

Here's the HTML:

<asp:DataGrid id="dgUsers" Runat="server" cssclass="datagrid" autogeneratecolumns="False" datakeyfield="UserID">
        <asp:BoundColumn ItemStyle-CssClass="datagriditem" HeaderStyle-cssclass="datagridheader" ReadOnly="True"
            DataField="UserID" HeaderText="ID"></asp:BoundColumn>
        <asp:TemplateColumn ItemStyle-CssClass="datagriditem" HeaderStyle-cssclass="datagridheader" HeaderText="Username">
                <asp:TextBox ID="txtEditUsername" Runat=server text='<%#Container.DataItem("Username")%>'>
                <asp:RequiredFieldValidator ID="rfvEditUsername" ControlToValidate="txtEditUsername" InitialValue="" ErrorMessage="Username is required."></asp:RequiredFieldValidator>
        <asp:TemplateColumn ItemStyle-CssClass="datagriditem" HeaderStyle-cssclass="datagridheader" HeaderText="Firstname">
                <asp:TextBox ID="txtEditFirstname" runat=server Text='<%#Container.DataItem("Firstname")%>'>
                <asp:RequiredFieldValidator ID="rfvEditFirstname" ControlToValidate="txtFirstUsername" InitialValue="" ErrorMessage="First name is required."></asp:RequiredFieldValidator>
        <asp:TemplateColumn ItemStyle-CssClass="datagriditem" HeaderStyle-cssclass="datagridheader" HeaderText="Lastname">
                <asp:TextBox ID="txtEditLastname" Runat=server Text='<%#Container.DataItem("Lastname")%>'>
                <asp:RequiredFieldValidator ID="rfvEditLastname" ControlToValidate="txtEditLastname" InitialValue="" ErrorMessage="Last name is required."></asp:RequiredFieldValidator>
        <asp:templatecolumn Visible="False">
                <asp:label runat=server ID="lblViewDeptID" text='<%#Container.DataItem("DeptID")%>'>
                <asp:label runat=server ID="lblEditDeptID" text='<%#Container.DataItem("DeptID")%>'>
        <asp:TemplateColumn ItemStyle-CssClass="datagriditem" HeaderStyle-cssclass="datagridheader" HeaderText="Department">
                <%# Container.DataItem("DeptName")%>
                <asp:DropDownList runat="server" id="ddlEditDeptID"></asp:DropDownList>
        <asp:TemplateColumn HeaderText="Admin" ItemStyle-CssClass="datagriditem" HeaderStyle-cssclass="datagridheader"
                <asp:Checkbox enabled=False runat=server id="chkUserAdminView" Checked='<%#Container.DataItem("Admin")%>'/>
                <asp:Checkbox runat=server id="chkUserAdminEdit" Checked='<%#Container.DataItem("Admin")%>' />
        <asp:EditCommandColumn runat="server" ItemStyle-CssClass="datagriditem" HeaderStyle-cssclass="datagridheader"
            headertext="Options" CancelText="Cancel" EditText="Edit" UpdateText="Update"></asp:EditCommandColumn>
Reply With Quote
  #2 (permalink)  
Old May 20th, 2006, 04:58 AM
Registered User
Join Date: May 2006
Location: Mumbai, Maharashtra, India.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

Check the Data Type you have used in the Table for for DeptId. If it is other than you have used in the code the exception is thrown.

Reply With Quote

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
Input string was not in a correct format Dwizz VB.NET 2002/2003 Basics 8 April 29th, 2010 05:56 AM
input string was not in a correct format kunal.net VS.NET 2002/2003 1 October 11th, 2005 12:18 AM
Input string was not in a correct format Dwizz VB.NET 2002/2003 Basics 2 April 4th, 2005 11:03 AM
"Input string was not in a correct format." keane Pro VB.NET 2002/2003 1 December 18th, 2004 08:45 PM

All times are GMT -4. The time now is 04:46 PM.

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