473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Error referencing Datagrid table cell

am working on code that will allow users to update data within the
datagrid. I have come across a few problems, some of them I have been
able to work out, but this last one is giving me trouble.

When a user clicks the edit button, I get an error 'Specified Cast Not
Valid'.
The code that generates the error is:
Dim strCompleted As String = CType(e.Item.Cells(6).Controls(1),

TextBox).Text
The code for the Data grid is below. I have tried changing the Controls

index to 0 and 2. In the debugger, I've done a gettype on the item
(which didn't seem to tell me much) as well as got the info for that
particular table cell and I see that it appears to be pointing at the
right control, but obviously something is not working.
Here is the code from the datagrid that is the control I am trying to
reference:
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Completed">
<HeaderStyle
HorizontalAlign="Center"></HeaderStyle>
<ItemTemplate>
<asp:label
runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "Completed") %>' ID="Label35" />
</ItemTemplate>
Any help is appreciated.
Thanks!
<asp:datagrid id=DataGrid1 style="Z-INDEX: 152;
LEFT: 16px;
POSITION: absolute; TOP: 488px"
tabIndex=-1 runat="server" Width="880px"
Height="56px"
DataSource="<%# DsFollowup1 %>"
DataMember="tblEntryFollowup" CellPadding="3"
BackColor="#DEBA84"
BorderWidth="1px"
CellSpacing="2" BorderStyle="None"
BorderColor="#DEBA84"
AutoGenerateColumns="False"
OnUpdateCommand="DataGrid_Update"
OnCancelCommand="DataGrid_Cancel"
OnEditCommand="DataGrid_Edit">
<SelectedItemStyle Font-Bold="True"
ForeColor="White"
BackColor="#738A9C"></SelectedItemStyle>
<ItemStyle ForeColor="#8C4510"
BackColor="#FFF7E7"></ItemStyle>
<HeaderStyle Font-Bold="True"
ForeColor="White"
BackColor="#A55129"></HeaderStyle>
<FooterStyle ForeColor="#8C4510"
BackColor="#F7DFB5"></FooterStyle>
<Columns>
<asp:TemplateColumn
HeaderText="ID">
<HeaderStyle
HorizontalAlign="Center"></HeaderStyle>
<ItemTemplate>
<asp:label
runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "ID") %>' ID="Label30" />
</ItemTemplate>
<EditItemTemplate>
<asp:label
runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "ID") %>' ID="LabelID" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Description">
<HeaderStyle
HorizontalAlign="Center"></HeaderStyle>
<ItemTemplate>
<asp:label
runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "Description") %>' ID="Label31" />

</ItemTemplate>
<EditItemTemplate>
<asp:textbox
runat="server" ReadOnly="False" Text='<%#
DataBinder.Eval(Container.DataItem, "Description") %>' ID="Textbox1" />

</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Who">
<HeaderStyle
HorizontalAlign="Center"></HeaderStyle>
<ItemTemplate>
<asp:label
runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "Who") %>' ID="Label32" />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox
runat="server" ReadOnly="False" Text='<%#
DataBinder.Eval(Container.DataItem, "Who") %>' ID="Textbox2" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="When">
<HeaderStyle
HorizontalAlign="Center"></HeaderStyle>
<ItemTemplate>
<asp:label
runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "dtWhen") %>' ID="Label33" />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox
runat="server" ReadOnly="False" Text='<%#
DataBinder.Eval(Container.DataItem, "dtWhen") %>' ID="Textbox3" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="WO">
<HeaderStyle
HorizontalAlign="Center"></HeaderStyle>
<ItemTemplate>
<asp:label
runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "WorkOrderNumber") %>'
ID="Label34" />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox
runat="server" ReadOnly="False" Text='<%#
DataBinder.Eval(Container.DataItem, "WorkOrderNumber") %>'
ID="Textbox5" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
HeaderText="Completed">
<HeaderStyle
HorizontalAlign="Center"></HeaderStyle>
<ItemTemplate>
<asp:label
runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "Completed") %>' ID="Label35" />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox
runat="server" ReadOnly="False" Text='<%#
DataBinder.Eval(Container.DataItem, "Completed") %>' ID="Completed" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn
Visible="False" HeaderText="Entry_ID">
<HeaderStyle
HorizontalAlign="Center"></HeaderStyle>
<ItemTemplate>
<asp:label
runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "Entry_ID") %>' ID="Label36" />
</ItemTemplate>
<EditItemTemplate>
<asp:label
runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "Entry_ID") %>' ID="Label37" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn
ButtonType="PushButton" UpdateText="Update"
HeaderText="Edit" CancelText="Cancel"

EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete"
ButtonType="PushButton"
HeaderText="Remove" CommandName="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Center"
ForeColor="#8C4510"
Mode="NumericPages"></PagerStyle>
</asp:datagrid>

Mar 24 '06 #1
3 1566
You are calling Ctype incorrectly

strTest = CType(DataItem, String)

Mar 24 '06 #2
It seems to work for the others. It's code I found on
aspnet.4guysfromrolla.com .

Dim intEntryID As String = e.Item.Cells(7).Text
Dim strDesc As String = CType(e.Item.Cells(2).Controls(1),
TextBox).Text
Dim strWho As String = CType(e.Item.Cells(3).Controls(1),
TextBox).Text
Dim strDt As String = CType(e.Item.Cells(4).Controls(1),
TextBox).Text
Dim strWO As String = CType(e.Item.Cells(5).Controls(1),
TextBox).Text
Dim strCompleted As String = CType(e.Item.Cells(6).Controls(0),
TextBox).Text

I can try taking the '.Text' off of that one, but don't know why it
would be different.

Mar 24 '06 #3
Well, did you "Try" my suggestion? Or try Text.ToString?

Mar 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Randy | last post by:
Hello All, I'm trying to discover the best way to handle the situation where you have a datagrid in your app and someone changes a cell but doesn't leave that cell (so there's the little pencil...
0
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically...
4
by: Kristoffer Arfvidson | last post by:
Im trying to get access to a table in codebehind, because the information in this table is different depending on what it says in the database... So, either I have to access it from codebehind,...
3
by: MattB | last post by:
Is there any way to reference a cell in a datagrid's ItemDataBound event by it's DataItem column name (e.item.DataItem("colname")). I need to set a cell's text to "" based on the contents of it's...
2
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to...
4
by: KatB | last post by:
Hi, in order to format my web page, I'm starting to use Flow layout so using html tables to space out controls, etc. When using grid layout, the following worked when it was just a datagrid. I...
5
by: Brian Henry | last post by:
I have a messaging application that has a data grid with information like an email list would have (from, subject, time sent, size) but the subject could be very long in theory, and then it would...
1
by: strout | last post by:
I know it's dumb ... sometimes frustrating I want the text and a dropdownlist align with both side of a table cell, i.e. text align left and dropdownlist align right. I cannot add more cells to...
3
by: JJ | last post by:
I have a datagrid on my form that displays its data from various tables within a specified dataset. That all works correclty. However, when one cell is selected prior to changed the displayed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.