Problem with editing datagrid <EditItemTemplate>

Discussion in 'ASP .Net Datagrid Control' started by tjonsek@phenom-biz.com, Mar 24, 2006.

  1. Guest

    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>
    , Mar 24, 2006
    #1
    1. Advertising

  2. Guest

    Re: Problem with editing datagrid <EditItemTemplate>

    sorry about the double post. I was trying to go back in history to
    another page and refreshed the wrong one.
    , Mar 24, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Trevor Hartman

    datagrid edititemtemplate for dates

    Trevor Hartman, Jul 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    362
    Trevor Hartman
    Jul 16, 2003
  2. Dave
    Replies:
    1
    Views:
    520
  3. Replies:
    0
    Views:
    572
  4. yamne
    Replies:
    0
    Views:
    132
    yamne
    Jun 17, 2004
  5. edititemtemplate datagrid problem

    , Sep 18, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    190
    Scott Mitchell [MVP]
    Sep 19, 2005
Loading...

Share This Page