RowCommand Event only fires for the first row in GridView

RowCommand Event only fires for the first row in GridView

Post by Chad Schar » Sat, 13 Oct 2007 08:15:36


I have a gridview control with one column. In that column are an
ItemTemplate and EditItemTemplate. The gridview is bound to an
ObjectDataSource using the DataSourceID property. I am not doing anything
special in the databinding event and the templates use basic framework
controls with either <%# Eval("property") %> or <%# Bind("property") %> in
the EditItemTemplate.

When there is more than one item bound to the gridview, any row other than
first one will not fire the RowCommand event unless I click each command
button twice. Upon the second click, the event will fire, but not the first.
When in edit mode (after 2 clicks on a button with CommandName="Edit") in a
row other than the first, when I click a button with CommandName="Update",
the page posts back, no events are fired and then all the fields in the edit
control are blank.

Any help with this would be greatly appreciated.

Regards,
Chad Scharf
 
 
 

RowCommand Event only fires for the first row in GridView

Post by SklHTkVTS » Sat, 13 Oct 2007 17:11:00

Hi Chad Scharf,

Could you pls check and let me know if code written in Page_load event is
within "IF NOT Page.ISPostBack" block.

If not add it and let me know the result. mostly it should solve.

Regards
JIGNESH

 
 
 

RowCommand Event only fires for the first row in GridView

Post by UGV0ZXIgQn » Sun, 14 Oct 2007 00:34:01

Chad,
Better not to provide samples as attachments - put the code inline in your
message. Many web-based and other newsgroup readers discard attachments.
-- Peter
Recursion: see Recursion
site: http://www.yqcomputer.com/
unBlog: http://www.yqcomputer.com/
BlogMetaFinder: http://www.yqcomputer.com/
 
 
 

RowCommand Event only fires for the first row in GridView

Post by Chad Schar » Sun, 14 Oct 2007 00:53:17

ops,

OK, here is the inline code. Thank's Peter. Also a quick note, I've tried
this with and without the UpdatePanel, and regardless, it has the same
behavior.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected object JSSafe(object text)

{

string safeText = text as string;

if (safeText != null)

{

safeText = safeText.Replace("'", "\\'");

safeText = safeText.Replace("\"", "\\\"");

return safeText;

}

return text;

}

protected string GetCopyMethod(object DataItem)

{

return
string.Format("setCopiedFields('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',{11},{12},{13},{14});
return false;",

JSSafe(DataBinder.Eval(DataItem, "AddressLine1")),

JSSafe(DataBinder.Eval(DataItem, "AddressLine2")),

JSSafe(DataBinder.Eval(DataItem, "City")),

JSSafe(DataBinder.Eval(DataItem, "State")),

DataBinder.Eval(DataItem, "Zip"),

DataBinder.Eval(DataItem, "StartDate"),

DataBinder.Eval(DataItem, "BaseOrFinalSalesPrice"),

JSSafe(DataBinder.Eval(DataItem, "LegalDescription")),

DataBinder.Eval(DataItem, "ApproximateClosingDate"),

JSSafe(DataBinder.Eval(DataItem, "HomebuyerFirstName")),

JSSafe(DataBinder.Eval(DataItem, "HomebuyerLastName")),

DataBinder.Eval(DataItem, "Grandfather").ToString().ToLower(),

DataBinder.Eval(DataItem, "SiteBuilt").ToString().ToLower(),

DataBinder.Eval(DataItem, "Manufactured").ToString().ToLower(),

DataBinder.Eval(DataItem, "Modular").ToString().ToLower()

);

}

protected bool IsPossibleDuplicate(object DataItem)

{

try

{

string addressLine1 = DataBinder.Eval(DataItem, "AddressLine1") as string;

if (addressLine1.Length > 6)

addressLine1 = addressLine1.Substring(0, 6);

string state = DataBinder.Eval(DataItem, "State") as string;

int homeId = (int)DataBinder.Eval(DataItem, "HomeID");

string filter = string.Format("HomeID < {0} AND AddressLine1 LIKE '{1}%' AND
State = '{2}'", homeId, addressLine1, state);

System.Data.DataRow[] found =
FormManager.Nos.MyNosForm.Step_2.Select(filter);

return found.Length > 0;

}

catch { return false; }

}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:ScriptManager ID="asdf" runat="server" />

<asp:UpdatePanel ID="asdff" runat="server">

<ContentTemplate>


<asp:GridView ID="HomesGridView" runat="server" DataKeyNames="HomeID"
DataSourceID="HomesDataSource"

ShowHeader="false"

AllowPaging="false"

AllowSorting="false"

AutoGenerateColumns="false"

GridLines="None"><%--OnRowCommand="HomesGridView_RowCommand"--%>

<EmptyDataTemplate>

You have not yet added any homes to this Notification of Starts, please use
the form below to input

and add a new home.

</EmptyDataTemplate>

<RowStyle CssClass="Row" />

<HeaderStyle CssClass="HeadingRow" />

<FooterStyle CssClass="GridFooter" />

<AlternatingRowStyle CssClass="AlternatingRow" />

<SelectedRowStyle CssClass="SelectedRow" />

<EditRowStyle CssClass="SelectedRow" />

<Columns>

<asp:TemplateField ShowHeader="false
 
 
 

RowCommand Event only fires for the first row in GridView

Post by Chad Schar » Wed, 17 Oct 2007 00:56:03

Any ideas out there?
 
 
 

RowCommand Event only fires for the first row in GridView

Post by Chad Schar » Wed, 17 Oct 2007 01:20:17

OK, just an update. I've narrowed the problem down to the Infragistics Web
Data Input controls in the <ItemTemplate>. When I comment them out,
everything works as expected. I guess I need to move this thread to
Infragistics support forums, unless anyone here may know what's going on.

Thanks,
Chad