473,756 Members | 4,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView added rows non-persistent

Hi all, I've got a really annoying problem that I need to fix sharpish.

I've got a GridView derived control which has a templated header and
footer. It works wonderfully on the first render but then the
header/footer vanish into thin air. If I add the header/footer
onDataBound then they disappear when I do a postback with no
databinding. If I add them during PreRender, then they persist, but one
of my data rows is emptied for each time I postback.

It feels like there's a rowIndex being kicked out of place, but I've
run reflector over CreateChildCont rols and given up all hope of
understanding it in the next week. Can anyone offer some help?

test code is below, apologies if it's not quite cut/paste ready but
it's lifted and munged from an active system. ASPX might need a quick
wrangle, but it looks good to my untrained eye.

cheers,

Flinky Wisty Pomm

--- code--

//
// this code is lifted from TwoHeadedGridVi ew by Matt Dotson,
// license and other code is available @
//
http://www.gotdotnet.com/workspaces/...b-1622eba20852
// I'm using this because it's a simpler form of my grid and has the
same problem

//############### ############### ###
// TwoHeadedGridVi ew.cs
//############### ############### ###
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Web.UI.W ebControls;
using System.Drawing;

namespace RealWorld.Grids
{
public class TwoHeadedGridVi ew : GridView
{
public string HeaderText
{
get
{
object val = this.ViewState["HeaderText "];
if (null == val)
{
return String.Empty;
}

return (String)val;
}
set
{
this.ViewState["HeaderText "] = value;
}
}

protected Table InnerTable
{
get
{
if (this.HasContro ls())
{
return (Table)this.Con trols[0];
}

return null;
}
}

protected override void OnDataBound(Eve ntArgs e)
{
base.OnDataBoun d(e);
this.CreateSeco ndHeader();
}

private void CreateSecondHea der()
{
GridViewRow row = new GridViewRow(0, -1,
DataControlRowT ype.Header, DataControlRowS tate.Normal);
TableCell th = new TableHeaderCell ();

th.HorizontalAl ign = HorizontalAlign .Center;
th.ColumnSpan = this.Columns.Co unt;
th.BackColor = Color.SteelBlue ;
th.ForeColor = Color.White;
th.Font.Bold = true;
th.Text = this.HeaderText ;
row.Cells.Add(t h);

this.InnerTable .Rows.AddAt(0, row);
}
}
}

// ############### ############### #######
// GridTest.cs
// ############### ############### #######

using System;
using System.Collecti ons.Generic;
using System.Web.UI;

using RealWorld.Grids ;

namespace Pages
{
public class GridTest : Page
{
protected TwoHeadedGridVi ew testgrid;

protected void Page_Load()
{
if(!IsPostBack)
BindGrid();
}

private void BindGrid()
{
Dictionary<stri ng,string> data = new
Dictionary<stri ng,string>(8);

data.Add("123", "abc");
data.Add("fred" ,"fredder");
data.Add("bing" ,"bong");
data.Add("foo", "bar");
data.Add("baz", "quux");
data.Add("oogle ","fooble") ;
data.Add("boogl e","zork");
data.Add("quuux ","quuuux") ;
data.Add("spam" ,"eggs");

testgrid.DataSo urce = data;
testgrid.DataBi nd();
}

protected void BindButtonClick ed(object sender, EventArgs e)
{
BindGrid();
}

}
}
// ############### ##########
// GridTest.aspx
// ############### ##########
<%@ Page language="c#" EnableViewState ="true" Inherits="Pages .GridTest"
MasterPageFile= "~/MasterPages/Agenda.Master"% >
<%@ Register TagPrefix="Real Grid" Namespace="Real World.Grids"
Assembly="Cogen tic.DSMSWeb.Cor e.Controls" %>

<html>
<head></head>
<body>
<form runat="server">

<RealGrid:TwoHe adedGridView runat="server" id="testgrid"
HeaderText="Fre d" />

<asp:Button id="btnRefresh " Text="Postback, no databind"
runat="server" />
<asp:Button id="btnBind" Text="Postback, rebind"
onclick="BindBu ttonClicked" runat="server" />

</form>
</body>
</html>

Apr 28 '06 #1
2 2761
Hi,

perhaps you could utilize same idea that I've used in one of my GridView
samples as I add grouping rows into the GridView (when GridView renders).
Same idea applies, you are just adding the first and last row where I am
adding the grouping headers

GridView Sort Grouping
http://aspadvice.com/blogs/joteke/ar.../11/15130.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Flinky Wisty Pomm" <Pa********@gma il.com> wrote in message
news:11******** *************@u 72g2000cwu.goog legroups.com...
Hi all, I've got a really annoying problem that I need to fix sharpish.

I've got a GridView derived control which has a templated header and
footer. It works wonderfully on the first render but then the
header/footer vanish into thin air. If I add the header/footer
onDataBound then they disappear when I do a postback with no
databinding. If I add them during PreRender, then they persist, but one
of my data rows is emptied for each time I postback.

It feels like there's a rowIndex being kicked out of place, but I've
run reflector over CreateChildCont rols and given up all hope of
understanding it in the next week. Can anyone offer some help?

test code is below, apologies if it's not quite cut/paste ready but
it's lifted and munged from an active system. ASPX might need a quick
wrangle, but it looks good to my untrained eye.

cheers,

Flinky Wisty Pomm

--- code--

//
// this code is lifted from TwoHeadedGridVi ew by Matt Dotson,
// license and other code is available @
//
http://www.gotdotnet.com/workspaces/...b-1622eba20852
// I'm using this because it's a simpler form of my grid and has the
same problem

//############### ############### ###
// TwoHeadedGridVi ew.cs
//############### ############### ###
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Web.UI.W ebControls;
using System.Drawing;

namespace RealWorld.Grids
{
public class TwoHeadedGridVi ew : GridView
{
public string HeaderText
{
get
{
object val = this.ViewState["HeaderText "];
if (null == val)
{
return String.Empty;
}

return (String)val;
}
set
{
this.ViewState["HeaderText "] = value;
}
}

protected Table InnerTable
{
get
{
if (this.HasContro ls())
{
return (Table)this.Con trols[0];
}

return null;
}
}

protected override void OnDataBound(Eve ntArgs e)
{
base.OnDataBoun d(e);
this.CreateSeco ndHeader();
}

private void CreateSecondHea der()
{
GridViewRow row = new GridViewRow(0, -1,
DataControlRowT ype.Header, DataControlRowS tate.Normal);
TableCell th = new TableHeaderCell ();

th.HorizontalAl ign = HorizontalAlign .Center;
th.ColumnSpan = this.Columns.Co unt;
th.BackColor = Color.SteelBlue ;
th.ForeColor = Color.White;
th.Font.Bold = true;
th.Text = this.HeaderText ;
row.Cells.Add(t h);

this.InnerTable .Rows.AddAt(0, row);
}
}
}

// ############### ############### #######
// GridTest.cs
// ############### ############### #######

using System;
using System.Collecti ons.Generic;
using System.Web.UI;

using RealWorld.Grids ;

namespace Pages
{
public class GridTest : Page
{
protected TwoHeadedGridVi ew testgrid;

protected void Page_Load()
{
if(!IsPostBack)
BindGrid();
}

private void BindGrid()
{
Dictionary<stri ng,string> data = new
Dictionary<stri ng,string>(8);

data.Add("123", "abc");
data.Add("fred" ,"fredder");
data.Add("bing" ,"bong");
data.Add("foo", "bar");
data.Add("baz", "quux");
data.Add("oogle ","fooble") ;
data.Add("boogl e","zork");
data.Add("quuux ","quuuux") ;
data.Add("spam" ,"eggs");

testgrid.DataSo urce = data;
testgrid.DataBi nd();
}

protected void BindButtonClick ed(object sender, EventArgs e)
{
BindGrid();
}

}
}
// ############### ##########
// GridTest.aspx
// ############### ##########
<%@ Page language="c#" EnableViewState ="true" Inherits="Pages .GridTest"
MasterPageFile= "~/MasterPages/Agenda.Master"% >
<%@ Register TagPrefix="Real Grid" Namespace="Real World.Grids"
Assembly="Cogen tic.DSMSWeb.Cor e.Controls" %>

<html>
<head></head>
<body>
<form runat="server">

<RealGrid:TwoHe adedGridView runat="server" id="testgrid"
HeaderText="Fre d" />

<asp:Button id="btnRefresh " Text="Postback, no databind"
runat="server" />
<asp:Button id="btnBind" Text="Postback, rebind"
onclick="BindBu ttonClicked" runat="server" />

</form>
</body>
</html>

Apr 29 '06 #2
Okay, I can add rows when the table renders, and obviously that works -
but I've got an ITemplate for my header/footer so I can add buttons,
links etc.

These need to be added during init or I can't fire server side events
from them. All the methods I want to get hold of in order to do that
are private - so I think I'm back to hunting for workarounds.

I can add the controls directly to the controlcollecti on of the
gridview and they appear in the right places, but they disappear
again... GAH! I'm beginning to think this is impossible.

Apr 29 '06 #3

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

Similar topics

1
3867
by: John_H | last post by:
Re: ASP.NET 2.0 I would like suggestions or code examples on how to collect a variable length list of input data (item# & item quantity specifically). I thought that I could accomplish this using a GridView that has ViewState enabled, an ObjectDataSource to process the submitted list, textboxes for getting new item data and an add button. Does this approach sound feasible or are there better alternatives? My problem is that I don't...
0
1886
by: yeltsin27 | last post by:
I need some advice on handling dynamically added controls in a GridView. My app takes an uploaded CSV file containing addresses, converts it to a DataTable, databinds the DataTable to a GridView, accepts information via dropdowns embedded in the first row of the GridView about which incoming fields should go to which database fields, and writes the data to the database. The incoming data has an arbitrary number of columns so I create...
0
8060
by: ssims | last post by:
I've got a GridView that's sorted by a stored procedure with ROW_NUMBER: PROCEDURE dbo.GetCalendarsByStatusIDPaged ( @startRowIndex int, @maximumRows int, @statusID int ) AS
8
7734
by: gerry | last post by:
The PagerSettings.Visible property is not being handled properly by the GridView control. The value assigned to this property is not applied until after a postback. Simplest test : .aspx containing a single gridview - enable paging and give enough data to page. add checkbox with auto postback enable add button with auto postback enable in the GridView1_PreRender method add the following : GridView1.HeaderRow.Enabled =
3
4074
by: shapper | last post by:
Hello, I need to loop though each row in a GridView and if the checkbox is a Template Field is checked I want to display the value of an invisible column named "LevelName". I tried everything I could think off but I always get an error or no value. Could someone please let me know what might be wrong?
2
2114
by: Blasting Cap | last post by:
I've got a gridview (that I converted over from a datagrid, which had been working properly), that is doubling up the number of rows returned. When it was running as a datagrid, the same code sent back the proper number of rows. The only thing different I am doing is to display the number of rows returned in the footer of the gridview. The Bindgrid is as follows: Sub BindGrid() Session("reportlevel") = Session("availabilityrptlevel")
1
3073
by: SachinSachin | last post by:
Hi All, I am implementing a custom gridview control, that emits some javascript to blink a row whenever a new row is added in gridview. The gridview is inside the <asp:updatepanel> for parital page rendering. The problem is when I put the gridview inside the updatepanel, I don't see the HTML table that is created as a result from rendering the gridviewcontrol and thus when new row is added, it does not blink, however when i just put the...
4
6082
by: tim.cavins | last post by:
I have a GridView populated by an ObjectDataSource. I am having issues passing the parameters to the objectdatasource. I have verified that the method is being called but none of the parameters are being populated. Integers are being passed as 0 and strings are empty regardless of what I changed them to in Edit mode on the GridView. My object method to perform the update:
1
7312
by: tucson | last post by:
I have a gridview that has a blank row with 2 input fields: file to upload, and a description of the file. They click Add and a new row is added, Remove and the row is removed. The problem is: When a new row is added, I loop through the existing gridview rows, store the data in a dataset, and rebind. In debug mode, I see the values I entered but when I rebind, it's not displayed in the gridview. Here's the code aspx code: ...
2
5339
by: Michael | last post by:
It seems that a gridview allows us to delete only a single row at a time. How to extend this functionality to select multiple rows and delete all of the selected rows in a single stroke? just like what hotmail web UI is doing now (having the option of selecting multiple rows (using the checkbox provided) and perform a set of operations on them)
0
9431
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9844
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8688
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, 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...
1
7226
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6514
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();...
0
5119
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3326
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2647
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.