Hi All,
I have a GridView inside the EditItemTemplat e of a FormView. Both FormView
and GridView are data bound using an ObjectDataSourc e. When the FormView's
ObjectDataSourc e object has a SelectParameter s with a SessionParamete r in
the parameters collection and the object stored in the Session is a
reference type,
the DataGrid fails to enter Line Editing mode.
Is this a bug? Is there a workaround for this problem?
I have created a minimal sample that demonstrates this problem.
I have 4 files in my sample.
1. Global.asax - initializes a Session state variable.
2. Default.aspx - holds the FormView and the GridView in it.
3. MyDataSource.cs - implements the data source object.
4. MyState.cs - a class to be saved in Session and passed in to the Select
statement using a SessionParamete r.
Here is the code:
Global.asax:
-----
<%@ Application Language="C#" %>
<script runat="server">
void Session_Start(o bject sender, EventArgs e)
{
Session["MySessionV ar"] = new MyState("MyValu e");
}
</script>
----
End Global.asax
Default.aspx:
----
<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Defau lt.aspx.cs"
Inherits="_Defa ult" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" DataSourceID="F ormViewODS"
DefaultMode="Ed it">
<EditItemTempla te>
<asp:GridView ID="GridView1" runat="server" DataSourceID="G ridViewODS"
AutoGenerateEdi tButton="true">
</asp:GridView>
<asp:ObjectData Source ID="GridViewODS " runat="server"
TypeName="MyDat aSource" SelectMethod="G ridViewSelect"
UpdateMethod="G ridRowUpdate">
</asp:ObjectDataS ource>
</EditItemTemplat e>
</asp:FormView>
<asp:ObjectData Source ID="FormViewODS " runat="server"
TypeName="MyDat aSource" SelectMethod="F ormViewSelectWi thSession"
EnableViewState ="false">
<SelectParamete rs>
<asp:SessionPar ameter Name="value" SessionField="M ySessionVar"
Type="Object" />
</SelectParameter s>
</asp:ObjectDataS ource>
</div>
</form>
</body>
</html>
----
End Default.aspx
MyDataSource.cs :
----
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
/// <summary>
/// Summary description for MyDataSource
/// </summary>
public static class MyDataSource
{
private static System.Data.Dat aTable data;
private static void CreateData()
{
data = new System.Data.Dat aTable();
data.Columns.Ad d("ID", typeof(int));
data.Columns.Ad d("Name", typeof(string)) ;
data.Columns.Ad d("Description" , typeof(string)) ;
data.Rows.Add(1 , "Name1", "Description1") ;
data.Rows.Add(2 , "Name2", "Description2") ;
data.Rows.Add(3 , "Name3", "Description3") ;
data.Rows.Add(4 , "Name4", "Description4") ;
}
public static System.Data.Dat aTable FormViewSelect( )
{
if (data == null) {
CreateData();
}
return data;
}
public static System.Data.Dat aTable FormViewSelectW ithSession(MySt ate
value)
{
if (data == null) {
CreateData();
}
return data;
}
public static System.Data.Dat aTable GridViewSelect( )
{
if (data == null) {
CreateData();
}
return data;
}
public static System.Data.Dat aTable GridViewSelectW ithSession(MySt ate
value)
{
if (data == null) {
CreateData();
}
return data;
}
public static void GridRowUpdate(i nt id, string name, string description)
{
}
}
----
End MyDataSource.cs
MyState.cs
----
using System;
public class MyState
{
public MyState()
{
Str = String.Empty;
}
public MyState(string str)
{
Str = str;
}
public string Str
{
get { return _str; }
set { _str = value; }
}
private string _str;
}
----
End MyState.cs
--
---
Adar Wesley 5 4671
Hi Adar,
Regarding on this issue, I have tested the page you provided and did repro
the same behavior as you mentioned. When the outer FormView choose to use
the Session Variable based select statement, the inner nested Gridview can
not turn into Edit mode. Currently, I'll do some further research on this
and will update you if I have any new progress.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Adar,
Regarding on this issue, I've performed some further research and haven't
got any progress so far. Currently, I will submit a bug request internally
for this issue. If there is any new information, I'll update you as soon as
possible.
Thanks for your understanding!
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Steven,
Thanks for the update.
The solution for this issue is not urgent for me. The behavior is not what I
expected, but I do have a workaround. I removed the SessionParamete r from
the ObjectDataSourc e parameter collection and from the method being invoked
and when I need to use the Session variable to get my data, I just access the
Session variable using HttpContext.Cur rent.Session.
This is less clean, but it works ...
Thanks again.
---
Adar Wesley
"Steven Cheng[MSFT]" wrote:
Hi Adar,
Regarding on this issue, I've performed some further research and haven't
got any progress so far. Currently, I will submit a bug request internally
for this issue. If there is any new information, I'll update you as soon as
possible.
Thanks for your understanding!
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks for your reply Adar,
Since I have submit the bug request, I'll continue to wait for some
further information on this from product team. I'll update the thread
whenever I get any further feedback from product team side. If you have
interests, still welcome to followup here.
Thanks again for your posting!
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Adar,
I just got some update from the product team engineer about the reported
bug of this issue. Here is some comments and a possible workaround from
them:
=============== =============== ===========
Looks like it¡¯s an issue with the order that events fire. The problem is
that when the FormView is being databound, the GridView is re-loaded.
You¡¯ll have to set the EditIndex after the controls are bound. Here¡¯s
the order of events:
FormView Init
GridView Init
FormView ItemCreated
FormView Load
GridView Load
GridView OnRowEditing ? EditIndex set here
FormView DataBinding
GridView Unload ?All your settings lost here
GridView Init
GridView Load
FormView ItemCreated
GridView OnDataBinding
Etc.
So even if you handle the OnRowEditing event on the GridView and force the
EditIndex property, when the FormView is databound, the GridView is
unloaded and you lose your changes.
I came up with a workaround that may work for your customer. See the
updated default.aspx page below. It stores the EditIndex in a private
variable and then sets the datagrid during the page Render.
<%@ Page Language="C#" AutoEventWireup ="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitl ed Page</title>
<script language="c#" runat="server">
private int _editIndex;
protected void GridView1_OnRow Editing(object sender,
GridViewEditEve ntArgs e)
{
_editIndex = e.NewEditIndex;
}
protected override void Render(HtmlText Writer writer)
{
if(Page.IsPostB ack)
((GridView)Form View1.FindContr ol("GridView1") ).EditIndex =
_editIndex;
base.Render(wri ter);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server"
DataSourceID="F ormViewODS" DefaultMode="Ed it">
<EditItemTempla te>
<asp:GridView ID="GridView1"
OnRowEditing="G ridView1_OnRowE diting" runat="server"
DataSourceID="G ridViewODS" AutoGenerateEdi tButton="true" >
</asp:GridView>
<asp:ObjectData Source ID="GridViewODS " runat="server"
TypeName="MyDat aSource"
SelectMethod="G ridViewSelect"
UpdateMethod="G ridRowUpdate">
</asp:ObjectDataS ource>
</EditItemTemplat e>
</asp:FormView>
<asp:ObjectData Source ID="FormViewODS " runat="server"
TypeName="MyDat aSource"
SelectMethod="F ormViewSelectWi thSession"
EnableViewState ="false">
<SelectParamete rs>
<asp:SessionPar ameter Name="value"
SessionField="M ySessionVar" Type="Object" />
</SelectParameter s>
</asp:ObjectDataS ource>
</div>
</form>
</body>
</html>
=============== =============== ===
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: P. Yanzick |
last post by:
Hello,
I've been playing with master/detail views as well as editing in the
gridview, and I ran across a strange problem that I am not exactly sure
where to go to try to solve.
I have 2 tables, a table of cars (pretty basic, an ID, a description, and a
Color ID) and a table of colors (Color ID, and a color description). I've
added a gridview and a detailsview as I'm playing with both and how to get
editing features to work the way I...
|
by: bigbrorpi |
last post by:
Hi
I have a FormView that contains a GridView. The GridView is populated
from an ObjectDataSource. Two of the columns in the GridView are not
bound, and the values used in Update mode come from dropdowns (inside
of ItemTemplates).
In my ObjectDataSource, I have Parameters for the bound fields, and
ControlParameters for the DDLs. I cannot seem to access the DDLs since
they are so nested. I've tried:
|
by: Dabbler |
last post by:
What's the best way to return to GridView after editing a detail record in a
FormView so the GridView shows the page with the edited record on it?
I'm using GridView with standard ObjectDataSource, no custom paging.
Thanks for any tips on this.
|
by: Kyle K. |
last post by:
I would like to build my data pages such that the top of the page
contains a GridView showing the data with 'Enable Select = true'.
Below that I would like to have a FormView, that by default is in
'Insert' mode for creating a new record.
If the user 'selects' a record in the GridView above, I would like to
set the FormView to 'Edit' mode with the 'selected' record data loaded
in it for editing. I would use the built-in editing...
|
by: joechipubik |
last post by:
I have a GridView in a FormView that has as its datasource a DataTable
that is stored in the session cache.
When I first load the page the GridView is displayed correctly, but on
subsequent loads the GridView does not display. I've debugged the
DataTable and even when it has data and is bound to the GridView, when
the page loads the GridView is not displayed. I set the datasource and
then bind the GridView. I've tried disabling the...
| |
by: DC |
last post by:
The problem
I'm using the .NET GridView and FormView objects for the first time and
im getting the error "An OleDbParameter with ParameterName '@ID' is not
contained by this OleDbParameterCollection" whenI try to write a new record.
Delete and Modify work fine its just the add record function causes the
error.
|
by: sck10 |
last post by:
Hello,
I have a web page that has a GridView and a FormView, each in its own
panel. The GridView shows a list of records in a database. When a row in
the GridView is selected the FormView Panel becomes visible.
pnlGridViewSearchList
pnlFormView
The problem that I am having is that if I set the FormView Panel's
|
by: LiamLiamLiam |
last post by:
G'day all.
I having a problem with my formview. I'll ty to explain my situation as best as i can.
I have a page with a search field at the top which is just a simple asp:textbox. Below that i have a gridview which displays the results of the search. if no search is entered, then the gridview shows all records. Below the gridview i have a formview for inserting and editing the records. when a user clicks on one of the records in the...
|
by: Polaris |
last post by:
Hi Experts:
I'm using asp.net 2.0 with Visual Studio 2005. I'm trying to use the
GridView to display data. I need to programmatically add rows into the
GridView. So far could not find a way to do it. I appreciate it if any one
can show a piece of code doing that.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |