GridView - FormView Problem

  • Thread starter Giorgio Parmeggiani
  • Start date
G

Giorgio Parmeggiani

Hi
I have a GridView and a FormView connected among them through a relationship
master/detail

The FormView has an ObjectDataSource with a ControlParameter connected to
the SelectedValue of the Grid:
<asp:ControlParameter ControlID="gridRichieste" Name="id" PropertyName="SelectedValue"
Type="Int32" />

When i click on the select button of the GridView all it correctly works
and the FormView correctly visualizes the detail.
But when I press the button of Edit of the FormView, the FormView disappears,
I have realized that, to the loading method of the detail, defined in the
ObjectDataSource, the parameter SelectedValue is passed to 0.

If I perform a formView.DataBind () in the event OnLoad of the page to every
postback, the FormView is also visualized correctly pressing the button of
Edit, but this is not a solution because to always perform the manual DataBind
determines other problems.

Besides if, in phase of debug, I stop the execution in the method OnLoad
of the page, immediately after having pressed Edit on the FormView, and I
visualize in the window of debug the FormView properties, continuing the
execution the FormView is correctly visualized!

Thank in advance
Giorgio
 
W

Walter Wang [MSFT]

Hi Giorgio,

Thank you for your post.

After reviewing your problem description, I'm still not clear about
following points:
1) Did you use strong typed DataSet and the generated TableAdapter as your
ObjectDataSource or use some custom Business Objects as ObjectDataSource?
2) In your last paragraph, do you mean that if you view the FormView
properties in debug window first, then the FormView will render with
correct SelectedValue?

If possible, could you please sending me a repro project?

I understand that this may be a lot of information to ask for at one time.
However, by collecting this information now, it will help us move more
quickly toward a solution. Thank you for your effort!


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Giorgio Parmeggiani

Hi Walter

Thank for your reply
After reviewing your problem description, I'm still not clear about
following points:
1) Did you use strong typed DataSet and the generated TableAdapter as
your
ObjectDataSource or use some custom Business Objects as
ObjectDataSource?

I have a custom Business Objects, the object retrieve his property value
from a SqlServer2005 database using NHibernate object

2) In your last paragraph, do you mean that if you view the FormView
properties in debug window first, then the FormView will render with
correct SelectedValue?

Here i have been wrong, i view NOT the FormView properties, but the GridView
properties first, then the FormView will render with correct SelectedValue.

The problem is that the GridView send to the FormView the correct SelectedValue
only if i display first the GridView properties in the debug window
If possible, could you please sending me a repro project?

I have tried to repeat the problem in a smaller project but i have not succeeded
there, therefore I send you the whole project and the database file, directly
to your email address because is too large for the newsgroup.

Thank very much

Giorgi
 
W

Walter Wang [MSFT]

Hi Giorgio,

Thank you for your sample code.

I've been able to reproduce the problem in your project and tracked down to
following reproducible code:

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="ListaRichieste.aspx.cs" Inherits="ListaRichieste" %>
<%@ Register Assembly="Gipasoft.Web.UI.WebControls.DateTimeSelector"
Namespace="Gipasoft.Web.UI.WebControls"
TagPrefix="cc2" %>
<%@ Register Assembly="Gipasoft.Web.UI20.WebControls"
Namespace="Gipasoft.Web.UI20.WebControls"
TagPrefix="cc1" %>
<%@ Register Assembly="eWorld.UI" Namespace="eWorld.UI" TagPrefix="ew" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Pagina senza titolo</title>
</head>
<body>
<form id="form2" runat="server">
<asp:FormView ID="fvDetail" runat="server" DataSourceID="odsDetail">
<ItemTemplate>
<asp:Label ID="lblCode" runat="server" Text='<%#
Eval("Anno") %>'></asp:Label>
<asp:LinkButton ID="lnkEdit" runat="server" Text="Edit"
CommandName="Edit"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtCode" runat="server" Text='<%#
Eval("Anno") %>'></asp:TextBox>
</EditItemTemplate>
</asp:FormView>
<asp:GridView ID="gvMaster" runat="server" DataSourceID="odsMaster"
DataKeyNames="Codice">
<Columns>
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="odsMaster" runat="server"
SelectMethod="GetBySQuery"
TypeName="Gipasoft.Business.RichiesteAutorizzazioneDAL.NHibernateDaoFactory+
RichiestaAutorizzazioneDaoNHibernate"
SortParameterName="orderExpression">
<SelectParameters>
<asp:ControlParameter ControlID="SearchSummary12"
Name="sQueryBlock" PropertyName="SearchCriteri"
Type="Object" />
<asp:parameter Name="orderExpression" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsDetail" runat="server"
UpdateMethod="Save" SelectMethod="GetById"

TypeName="Gipasoft.Business.RichiesteAutorizzazioneDAL.NHibernateDaoFactory+
RichiestaAutorizzazioneDaoNHibernate"

DataObjectTypeName="Gipasoft.Business.RichiesteAutorizzazione.RichiestaAutor
izzazione">
<SelectParameters>
<asp:ControlParameter ControlID="gvMaster" Name="id"
PropertyName="SelectedValue"
Type="Int32" />
<asp:parameter DefaultValue="false" Name="shouldLock"
Type="Boolean" />
</SelectParameters>
</asp:ObjectDataSource>
<cc1:SearchSummary ID="SearchSummary12" runat="server"
EnableViewState="False">
</cc1:SearchSummary>
</form>
</body>
</html>



I've found changing the order of FormView and GridView, or odsMaster and
odsDetail will fix this problem.

In the above sample code, you will find that even the Select method of
GridView will not display the FormView, but if you handle the
SelectedIndexChanged event of GridView and access its SelectedValue
property (like you did in your code), then the FormView will be updated
when the GridView's SelectedIndex is changed. Also, if you handle
FormView's ItemCommand event and access GridView's SelectedValue property,
the EditItemTemplate of FormView will also work correctly. That's why the
problem doesn't occur when you break in Page_Load and watch GridView.

I didn't find the root cause of this problem yet, I was unable to reproduce
this problem by using two simpler ObjectDataSource controls. I suspect this
may be related to the ControlParameter of odsMaster or the underlying
ObjectDataSource controls you are using from the DAL components.

Since I don't have the source code of the SearchSummary control and the DAL
components, I cannot debug this problem further. I recommend you check the
pattern of this scenario and create a smaller repro project so that we can
find out the real cause of this problem. Thank you for your effort on this.



Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Giorgio Parmeggiani

Thank very much Walter

Yuo are reason the problem is due to the SearchSummary webcontrol.
The SearchSummary loop through all the page controls and this cause the problem

I don't understand the reason of it since is the grid that the formview are
immediately excluded by the loop, perhaps the problem occurs because the
component tries to also read the collections of controls of the grid and
the formview.

I have change the order of odsMaster and odsDetail and this fix this problem

Thank very much

Giorgio
 
W

Walter Wang [MSFT]

Hi Giorgio,

Thank you for letting me know that the SearchSummary control is causing the
problem. I'll try to do more research on it and see if it can reproduce the
problem more easily. Thanks for your patience and understanding.

Have a nice day!


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Hi Giorgio,

Sorry for reply so late.

I've done more research on the ControlParameter of the first
ObjectDataSource but still failed to reproduce the issue using a custom
server control. If you want to find the real cause of this problem, you may
need to send me the source code of the SearchSummary. Thank you for your
understanding and patience.



Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Giorgio Parmeggiani

Hi
Also excuse me you for the delay, but I have now seen only your message

I send you the complete source code of SearchSummary.

Thank you very much

Giorgio
 
W

Walter Wang [MSFT]

Hi Giorgio,

Thank you for your update.

I haven't received your mail yet, would you please sending it again? Thanks!

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top