Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Gridview - empty control data when saving?

Reply
Thread Tools

Gridview - empty control data when saving?

 
 
Knoxy
Guest
Posts: n/a
 
      07-30-2008
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();
}
 
Reply With Quote
 
 
 
 
Knoxy
Guest
Posts: n/a
 
      07-30-2008
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...
 
Reply With Quote
 
 
 
 
Knoxy
Guest
Posts: n/a
 
      07-30-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Empty gridview cells and checking for empty string Savvoulidis Iordanis ASP .Net 1 09-05-2008 06:15 AM
How to show GridView bound to empty data source? (2.0) Tomasz Jastrzebski ASP .Net 13 01-19-2007 06:56 PM
DetailsView ASP Control and an empty field not an empty record. ButlerDJIAM ASP .Net 0 11-09-2006 06:40 PM
How to display GridView when Data is empty ad ASP .Net 1 09-13-2006 08:23 AM
empty/non-empty element John XML 1 07-16-2003 10:23 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57