Gridview - empty control data when saving?

  • Thread starter Thread starter Knoxy
  • Start date Start date
K

Knoxy

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();
}
 
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...
 
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 :-)
 
Back
Top