Gridview - empty control data when saving?

Discussion in 'ASP .Net' started by Knoxy, Jul 30, 2008.

  1. Knoxy

    Knoxy Guest

    Hi guys,
    I'm using a gridview to do some inline editing. The data binds okay,
    its goes into edit mode and cancel okay. I'm using my own custom
    commandName, "save", and it picks this up okay. Don't want to use the
    built in "update" command. Trouble is when I go to access the form
    fields (textboxes etc), there isn't any data there (ie text in the
    textbox), I can access them though, I guess I'm missing an event
    somewhere.

    I've stripped out the necessary bits of code that i've used and added
    it below.

    Any ideas most appreciated, driving me nuts.
    Regards.

    **** UI ****
    ..
    ..
    ..

    <asp:TemplateField HeaderStyle-Width="150">
    <ItemTemplate><%# Eval("EmailAddress") %></ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtEmailAddress" runat="server" Text='<%#
    Eval("EmailAddress") %>' />
    </EditItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField ItemStyle-Width="80" ItemStyle-
    HorizontalAlign="Right">
    <ItemTemplate>
    <asp:LinkButton CommandName="Edit" CommandArgument='<%#
    Container.DataItemIndex %>' runat="server">
    <asp:Image ID="Image1" runat="server" ImageUrl="~/Content/Images/
    document_edit.png" />
    </asp:LinkButton>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:LinkButton CommandName="Save" CommandArgument='<%#
    Container.DataItemIndex %>' runat="server">
    <asp:Image ID="Image2" runat="server" ImageUrl="~/Content/Images/
    document_ok.png" />
    </asp:LinkButton>
    &nbsp;
    <asp:LinkButton CommandName="Cancel" CommandArgument='<%#
    Container.DataItemIndex %>' runat="server">
    <asp:Image ID="Image3" runat="server" ImageUrl="~/Content/Images/
    undo.png" />
    </asp:LinkButton>
    </EditItemTemplate>
    </asp:TemplateField>

    <asp:ObjectDataSource .... SelectMethod="GetAlarms" .... />




    **** code behind ****
    protected void RowCommand(object sender, GridViewCommandEventArgs e)
    {
    int index = int.Parse(e.CommandArgument.ToString());
    GridViewRow row = gvData.Rows[index];
    switch (e.CommandName.ToLower())
    {
    case "save":
    UpdateAlarmMapping(row);
    gvData.EditIndex = -1;
    gvData.DataBind();
    break;
    }
    }

    private void UpdateAlarmMapping(GridViewRow row)
    {
    Alarm alarm = new Alarm();
    alarm.Enabled = ((CheckBox)row.Cells[2].Controls[0]).Checked;
    alarm.EmailAddress =
    ((TextBox)row.FindControl("txtEmailAddress")).Text;
    alarm.MobileNumber =
    ((TextBox)row.FindControl("txtMobileNumber")).Text;
    alarm.AlarmNo =
    int.Parse(((Literal)row.FindControl("litAlarmNo")).Text);

    bool ok = alarm.SaveAlarmMapping();
    }
     
    Knoxy, Jul 30, 2008
    #1
    1. Advertisements

  2. Knoxy

    Knoxy Guest

    Seems JQuery is causing some kind of conflict, I have my gridview in a
    modal "window" (ie, div), a bunch of stuff is injected into the DOM
    when it finds the div id containing my grid - i remove the call to do
    this and it works fine

    Now I have a different problem...
     
    Knoxy, Jul 30, 2008
    #2
    1. Advertisements

  3. Knoxy

    Knoxy Guest

    Sorted.

    Seems jquery UI dialog will tear the div containing my gridview out
    from where it was in the DOM and inject it directly onto the BODY tag.
    So, because it's outside of the FORM tag, the fields weren't getting
    posted during postback

    Was able to get around this by editing the jquery library itself and
    appending the dialog to the form id "aspnetForm".
    Changed .appendTo(document.body) to .appendTo('#aspnetForm')

    Seems to work so far :)
     
    Knoxy, Jul 30, 2008
    #3
    1. Advertisements

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. John Kandell
    Replies:
    4
    Views:
    4,439
    eeebop
    Dec 10, 2004
  2. Luis Esteban Valencia
    Replies:
    0
    Views:
    2,744
    Luis Esteban Valencia
    Jan 6, 2005
  3. ad
    Replies:
    1
    Views:
    3,386
    Eliyahu Goldin
    Sep 13, 2006
  4. Replies:
    0
    Views:
    386
  5. ButlerDJIAM
    Replies:
    0
    Views:
    712
    ButlerDJIAM
    Nov 9, 2006
  6. Savvoulidis Iordanis

    Empty gridview cells and checking for empty string

    Savvoulidis Iordanis, Sep 5, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    746
    Savvoulidis Iordanis
    Sep 5, 2008
  7. vignesh86

    Saving gridview data on postback

    vignesh86, Jul 21, 2010, in forum: .NET
    Replies:
    0
    Views:
    1,300
    vignesh86
    Jul 21, 2010
  8. Lovely Angel For You

    Saving Images While Saving ASP Pages !

    Lovely Angel For You, Oct 2, 2003, in forum: ASP General
    Replies:
    1
    Views:
    356
    Curt_C [MVP]
    Oct 3, 2003
Loading...