lynnton
asked on
cast is not valid
Hi,
What does Specified cast is not valid. means?
how can we get the value of First Break, Lunch break, and second break? using DirectCast(e.Item.Cells( ?).Controls( ?),TextBox)
Thanks.
Server Error in '/' Application.
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
Specified cast is not valid.
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.InvalidCastExceptio n: Specified cast is not valid.
Source Error:
Line 120: 'Dim txtlunch As TextBox = DirectCast(e.Item.Cells(6) .Controls( 0),TextBox )
Line 121: 'Dim txtlast As TextBox = DirectCast(e.Item.Cells(7) .Controls( 0),TextBox )
Line 122: if isdate(DirectCast(e.Item.C ells(5).Co ntrols(0), TextBox)) or _
Line 123: isdate(DirectCast(e.Item.C ells(6).Co ntrols(0), TextBox)) or _
Line 124: isdate(DirectCast(e.Item.C ells(7).Co ntrols(7), TextBox)) then
Source File: c:\inetpub\wwwroot\shiftvi ew.aspx Line: 122
<asp:DataGrid id="DataGrid1" runat="server" Font-Names="Verdana" Font-Size="XX-Small" DataKeyField="operatorshif tid" AutoGenerateColumns="False " CellPadding="4" onPageIndexChanged="pageGr id" AllowPaging="True" PageSize="50" OnDeleteCommand="manage_de lete" OnUpdateCommand="manage_up date" OnCancelCommand="manage_ca ncel_edit" OnEditCommand="manage_edit " OnItemDataBound="manage_It emDataBoun d" GridLines="Horizontal">
<HeaderStyle font-bold="True"></HeaderS tyle>
<Columns>
<asp:BoundColumn DataField="operatorid" ReadOnly="True" HeaderText="Operator ID"></asp:BoundColumn>
<asp:BoundColumn DataField="operatorname" ReadOnly="True" HeaderText="Operator Name"></asp:BoundColumn>
<asp:BoundColumn DataField="shiftdate" ReadOnly="True" HeaderText="Shift Date"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Start Time">
<ItemTemplate>
<%# Container.DataItem("startt ime")%>
</ItemTemplate>
<EditItemTemplate>
<asp:Label id="lblSelected1" visible="false" text=<%# DataBinder.Eval(Container. DataItem, "starttime") %> runat="server"/>
<asp:DropDownList ID="DropDownList1" runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="First Break">
<ItemTemplate>
<asp:Label runat="server" text='<%# DataBinder.Eval(Container, "DataItem.break1") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Width="80px" Text='<%# DataBinder.Eval(Container, "DataItem.break1") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Lunch Break">
<ItemTemplate>
<asp:Label runat="server" text='<%# DataBinder.Eval(Container, "DataItem.lunch") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Width="80px" Text='<%# DataBinder.Eval(Container, "DataItem.lunch") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Second Break">
<ItemTemplate>
<asp:Label runat="server" text='<%# DataBinder.Eval(Container, "DataItem.break2") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Width="80px" Text='<%# DataBinder.Eval(Container, "DataItem.break2") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="endtime" ReadOnly="True" HeaderText="End Time"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:Edit CommandCol umn>
<asp:ButtonColumn Text="Delete" CommandName="Delete"></asp :ButtonCol umn>
</Columns>
<PagerStyle horizontalalign="Right" position="TopAndBottom" pagebuttoncount="20" mode="NumericPages"></Page rStyle>
</asp:DataGrid>
What does Specified cast is not valid. means?
how can we get the value of First Break, Lunch break, and second break? using DirectCast(e.Item.Cells( ?).Controls( ?),TextBox)
Thanks.
Server Error in '/' Application.
--------------------------
Specified cast is not valid.
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.InvalidCastExceptio
Source Error:
Line 120: 'Dim txtlunch As TextBox = DirectCast(e.Item.Cells(6)
Line 121: 'Dim txtlast As TextBox = DirectCast(e.Item.Cells(7)
Line 122: if isdate(DirectCast(e.Item.C
Line 123: isdate(DirectCast(e.Item.C
Line 124: isdate(DirectCast(e.Item.C
Source File: c:\inetpub\wwwroot\shiftvi
<asp:DataGrid id="DataGrid1" runat="server" Font-Names="Verdana" Font-Size="XX-Small" DataKeyField="operatorshif
<HeaderStyle font-bold="True"></HeaderS
<Columns>
<asp:BoundColumn DataField="operatorid" ReadOnly="True" HeaderText="Operator ID"></asp:BoundColumn>
<asp:BoundColumn DataField="operatorname" ReadOnly="True" HeaderText="Operator Name"></asp:BoundColumn>
<asp:BoundColumn DataField="shiftdate" ReadOnly="True" HeaderText="Shift Date"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Start Time">
<ItemTemplate>
<%# Container.DataItem("startt
</ItemTemplate>
<EditItemTemplate>
<asp:Label id="lblSelected1" visible="false" text=<%# DataBinder.Eval(Container.
<asp:DropDownList ID="DropDownList1" runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="First Break">
<ItemTemplate>
<asp:Label runat="server" text='<%# DataBinder.Eval(Container,
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Width="80px" Text='<%# DataBinder.Eval(Container,
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Lunch Break">
<ItemTemplate>
<asp:Label runat="server" text='<%# DataBinder.Eval(Container,
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Width="80px" Text='<%# DataBinder.Eval(Container,
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Second Break">
<ItemTemplate>
<asp:Label runat="server" text='<%# DataBinder.Eval(Container,
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Width="80px" Text='<%# DataBinder.Eval(Container,
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="endtime" ReadOnly="True" HeaderText="End Time"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:Edit
<asp:ButtonColumn Text="Delete" CommandName="Delete"></asp
</Columns>
<PagerStyle horizontalalign="Right" position="TopAndBottom" pagebuttoncount="20" mode="NumericPages"></Page
</asp:DataGrid>
Are u trying to make a validaton of datetimes? Why dont u use regular expression validators?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
djhex,
We need to get the data first :-)
how can we get the value of First Break, Lunch break, and second break? using DirectCast(e.Item.Cells( ?).Controls( ?),TextBox)
Thanks.
We need to get the data first :-)
how can we get the value of First Break, Lunch break, and second break? using DirectCast(e.Item.Cells( ?).Controls( ?),TextBox)
Thanks.
I don't know what DirectCast is either, but can't you just do this?
if isdate(cType(e.Item.Cells( 5).Control s(0),TextB ox))
Also... a lot of times the index isn't what you think when you are looking in a datagrid. If you can just reference the control by name.
if isdate(cType(e.Item.FindCo ntrol("tex tboxname") , TextBox))
if isdate(cType(e.Item.Cells(
Also... a lot of times the index isn't what you think when you are looking in a datagrid. If you can just reference the control by name.
if isdate(cType(e.Item.FindCo
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oops, I forgot something
if isdate(cType(e.Item.FindCo ntrol("tex tboxname") , TextBox).text) then
Try that.
if isdate(cType(e.Item.FindCo
Try that.
ASKER
thrill_house,
sadly :End of statement expected
Thanks.
Server Error in '/' Application.
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30205: End of statement expected.
Source Error:
Line 117: '--for OnUpdateCommand (SP_team_editonupdate)
Line 118: Sub manage_update( s As Object, e As DataGridCommandEventArgs)
Line 119: dim YourVarLbl string CType(e.item.FindControl(" txtfb"),te xtbox).tex t
Line 120: 'Dim txtlunch As TextBox = DirectCast(e.Item.Cells(6) .Controls( 0),TextBox )
Line 121: 'Dim txtlast As TextBox = DirectCast(e.Item.Cells(7) .Controls( 0),TextBox )
Source File: c:\inetpub\wwwroot\shiftvi ew.aspx Line: 119
<asp:Label runat="server" text='<%# DataBinder.Eval(Container, "DataItem.break1") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtfb" runat="server" Width="80px" Text='<%# DataBinder.Eval(Container, "DataItem.break1") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Lunch Break">
<ItemTemplate>
sadly :End of statement expected
Thanks.
Server Error in '/' Application.
--------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30205: End of statement expected.
Source Error:
Line 117: '--for OnUpdateCommand (SP_team_editonupdate)
Line 118: Sub manage_update( s As Object, e As DataGridCommandEventArgs)
Line 119: dim YourVarLbl string CType(e.item.FindControl("
Line 120: 'Dim txtlunch As TextBox = DirectCast(e.Item.Cells(6)
Line 121: 'Dim txtlast As TextBox = DirectCast(e.Item.Cells(7)
Source File: c:\inetpub\wwwroot\shiftvi
<asp:Label runat="server" text='<%# DataBinder.Eval(Container,
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtfb" runat="server" Width="80px" Text='<%# DataBinder.Eval(Container,
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Lunch Break">
<ItemTemplate>
I want to know why dont u make it the other Way.
You can even validate on the client
You can even validate on the client
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Class DateTimeUtils
Public Shared Function IsDate(ByVal strDate As String) As Boolean
Dim dtDate As DateTime
Dim bValid As Boolean = True
Try
dtDate = DateTime.Parse(strDate)
Catch eFormatException As FormatException
' the Parse method failed => the string strDate cannot be converted to a date.
bValid = False
End Try
Return bValid
End Function
End Class
Public Shared Function IsDate(ByVal strDate As String) As Boolean
Dim dtDate As DateTime
Dim bValid As Boolean = True
Try
dtDate = DateTime.Parse(strDate)
Catch eFormatException As FormatException
' the Parse method failed => the string strDate cannot be converted to a date.
bValid = False
End Try
Return bValid
End Function
End Class
dim res as string= e.Item.Cells(5).Controls(0
dim dat as datetime = convert.todatetime(res)