Problem with editing datagrid <EditItemTemplate>

T

tjonsek

I 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>
 
T

tjonsek

sorry about the double post. I was trying to go back in history to
another page and refreshed the wrong one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top