473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

GridView not entering Line Editing mode when inside FormView


Hi All,

I have a GridView inside the EditItemTemplate of a FormView. Both FormView
and GridView are data bound using an ObjectDataSource. When the FormView's
ObjectDataSource object has a SelectParameters with a SessionParameter 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 SessionParameter.

Here is the code:

Global.asax:
-----
<%@ Application Language="C#" %>
<script runat="server">
void Session_Start(object sender, EventArgs e)
{
Session["MySessionVar"] = new MyState("MyValue");
}
</script>
----
End Global.asax

Default.aspx:
----
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" DataSourceID="FormViewODS"
DefaultMode="Edit">
<EditItemTemplate>
<asp:GridView ID="GridView1" runat="server" DataSourceID="GridViewODS"
AutoGenerateEditButton="true">
</asp:GridView>
<asp:ObjectDataSource ID="GridViewODS" runat="server"
TypeName="MyDataSource" SelectMethod="GridViewSelect"
UpdateMethod="GridRowUpdate">
</asp:ObjectDataSource>
</EditItemTemplate>
</asp:FormView>
<asp:ObjectDataSource ID="FormViewODS" runat="server"
TypeName="MyDataSource" SelectMethod="FormViewSelectWithSession"
EnableViewState="false">
<SelectParameters>
<asp:SessionParameter Name="value" SessionField="MySessionVar"
Type="Object" />
</SelectParameters>
</asp:ObjectDataSource>
</div>
</form>
</body>
</html>
----
End Default.aspx

MyDataSource.cs:
----
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for MyDataSource
/// </summary>
public static class MyDataSource
{
private static System.Data.DataTable data;

private static void CreateData()
{
data = new System.Data.DataTable();
data.Columns.Add("ID", typeof(int));
data.Columns.Add("Name", typeof(string));
data.Columns.Add("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.DataTable FormViewSelect()
{
if (data == null) {
CreateData();
}
return data;
}

public static System.Data.DataTable FormViewSelectWithSession(MyState
value)
{
if (data == null) {
CreateData();
}
return data;
}

public static System.Data.DataTable GridViewSelect()
{
if (data == null) {
CreateData();
}
return data;
}

public static System.Data.DataTable GridViewSelectWithSession(MyState
value)
{
if (data == null) {
CreateData();
}
return data;
}

public static void GridRowUpdate(int 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

May 10 '07 #1
5 4661
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.
May 11 '07 #2
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.

May 16 '07 #3
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 SessionParameter from
the ObjectDataSource 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.Current.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.

May 16 '07 #4
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.

May 17 '07 #5
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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script language="c#" runat="server">
private int _editIndex;

protected void GridView1_OnRowEditing(object sender,
GridViewEditEventArgs e)
{
_editIndex = e.NewEditIndex;
}

protected override void Render(HtmlTextWriter writer)
{
if(Page.IsPostBack)
((GridView)FormView1.FindControl("GridView1")).Edi tIndex =
_editIndex;
base.Render(writer);

}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server"
DataSourceID="FormViewODS" DefaultMode="Edit">
<EditItemTemplate>
<asp:GridView ID="GridView1"
OnRowEditing="GridView1_OnRowEditing" runat="server"
DataSourceID="GridViewODS" AutoGenerateEditButton="true" >
</asp:GridView>
<asp:ObjectDataSource ID="GridViewODS" runat="server"
TypeName="MyDataSource"
SelectMethod="GridViewSelect"
UpdateMethod="GridRowUpdate">
</asp:ObjectDataSource>
</EditItemTemplate>
</asp:FormView>

<asp:ObjectDataSource ID="FormViewODS" runat="server"
TypeName="MyDataSource"
SelectMethod="FormViewSelectWithSession"
EnableViewState="false">
<SelectParameters>
<asp:SessionParameter Name="value"
SessionField="MySessionVar" Type="Object" />
</SelectParameters>
</asp:ObjectDataSource>
</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.

May 28 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
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...
2
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...
2
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...
1
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...
1
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...
0
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...
2
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...
0
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...
3
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.