|
-
Mar 31st, 2005, 01:04 AM
#1
Thread Starter
Lively Member
Help - DataGrid - Specified cast is not valid. *Resolved*
I have been pulling my hair out over this and have yet to find a resolution. The code was working until I changed the bound until I started tweaking the DataGrid.
The ASP page code is:
VB Code:
<asp:datagrid id="DataGrid1" runat="server" GridLines="Vertical" DataKeyField="City" AllowPaging="True"
PageSize="6" BackColor="White" CellPadding="3" width="80%" BorderStyle="None" BorderWidth="1px"
BorderColor="#999999" AutoGenerateColumns="False">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#000084"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton runat="server" Text="Edit" CommandName="Edit" CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton runat="server" Text="Update" CommandName="Update"></asp:LinkButton>
<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="false"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton runat="server" Text="Delete" CommandName="Delete" CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="City">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.City") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.City") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="State/Country">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.State/Country") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.State/Country") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Contact Email">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Contact Email") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Contact Email") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Active?" ReadOnly="True" HeaderText="Active?"></asp:BoundColumn>
</Columns>
<PagerStyle Font-Size="Smaller" HorizontalAlign="Center" ForeColor="Black" BackColor="#999999"
Mode="NumericPages"></PagerStyle>
</asp:datagrid>
The DataGrid_Update Sub line of code that blows up:
VB Code:
Was working before my changes to the Datagrids look and feel:
Dim City As String = Server.UrlEncode(CType(E.Item.Cells(2).Controls(0), TextBox).Text)
Tried this option as well:
Dim city As TextBox = CType(E.Item.Cells(2).Controls(0), TextBox)
Dim strcity As String = Server.UrlEncode(city.Text)
What am i doing wrong??
Last edited by Tenebrosity; Apr 1st, 2005 at 12:19 AM.
Reason: Detailed title
Tenebrosity
"But the plans were on display ..."
"On display? I eventually had to go down to the cellar to find them, With a torch."
"That's the display department. The lights had probably gone out."
"So had the stairs."
"But look, you found the notice didn't you?"
"Yes," said Arthur, "yes I did. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying Beware of the Leopard."
-
Mar 31st, 2005, 09:36 AM
#2
Thread Starter
Lively Member
Re: Help - DataGrid - Specified cast is not valid.
I have also tried this method.
VB Code:
Dim tbCity As TextBox
tbCity = E.Item.Cells(3).Controls(0)
Dim strCity As String = tbCity.Text.Trim
Any Ideas? I am so frustrated right now.
Tenebrosity
"But the plans were on display ..."
"On display? I eventually had to go down to the cellar to find them, With a torch."
"That's the display department. The lights had probably gone out."
"So had the stairs."
"But look, you found the notice didn't you?"
"Yes," said Arthur, "yes I did. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying Beware of the Leopard."
-
Mar 31st, 2005, 04:42 PM
#3
Thread Starter
Lively Member
Re: Help - DataGrid - Specified cast is not valid.
Tenebrosity
"But the plans were on display ..."
"On display? I eventually had to go down to the cellar to find them, With a torch."
"That's the display department. The lights had probably gone out."
"So had the stairs."
"But look, you found the notice didn't you?"
"Yes," said Arthur, "yes I did. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying Beware of the Leopard."
-
Mar 31st, 2005, 07:02 PM
#4
Member
Re: Help - DataGrid - Specified cast is not valid.
try giving IDs to the controls like
<EditItemTemplate>
<asp:TextBox ID="City" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.City") %>'></asp:TextBox>
</EditItemTemplate>
and then in the code
tbCity = directcast(e.Item.FindControl("City"),TextBox)
Lemme know if that works.
Maybe if you'd stop breathing and die for a change I wouldn't be so pissed off all the time.
www.mredkj.com
-
Apr 1st, 2005, 12:16 AM
#5
Thread Starter
Lively Member
Re: Help - DataGrid - Specified cast is not valid.
Thats got it! Thanks!
I was ready to toss my laptop across the room. hehehe
Tenebrosity
"But the plans were on display ..."
"On display? I eventually had to go down to the cellar to find them, With a torch."
"That's the display department. The lights had probably gone out."
"So had the stairs."
"But look, you found the notice didn't you?"
"Yes," said Arthur, "yes I did. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying Beware of the Leopard."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|