473,382 Members | 1,786 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,382 software developers and data experts.

Deleting rows from an unbound gridview

I have a gridview on my form which I have populated using a
datareader. What I would like to do is to be able to remove specified
records from the gridview, without affecting the source of the data.

I'm a bit confused about how to go about removing the rows - all the
google searches I have done so far seem to assume that the grid view
is bound and the programmer wants to delete the data from the original
source. Is there any easy way to do this - i.e. delete row x from the
grid?

I'd be grateful for any help with this!

Greg.

Feb 1 '07 #1
11 2527
"Greg" <sp**********@yahoo.co.ukwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
>I have a gridview on my form which I have populated using a
datareader. What I would like to do is to be able to remove specified
records from the gridview, without affecting the source of the data.
Do you mean you want to remove the rows client-side once the page has
actually been rendered, or do you want to prevent certain rows from being
rendered to the page as the data is being bound...?
Feb 1 '07 #2
On 1 Feb, 19:19, "Mark Rae" <m...@markNOSPAMrae.comwrote:
"Greg" <spammesil...@yahoo.co.ukwrote in message

news:11**********************@a75g2000cwd.googlegr oups.com...
I have a gridview on my form which I have populated using a
datareader. What I would like to do is to be able to remove specified
records from the gridview, without affecting the source of the data.

Do you mean you want to remove the rows client-side once the page has
actually been rendered, or do you want to prevent certain rows from being
rendered to the page as the data is being bound...?
The latter, I suppose, but what I was hoping to do was to actually
remove the rows from the server side grid view object, not just refuse
to render those rows.

Thanks,

Greg.

Feb 1 '07 #3
"Greg" <sp**********@yahoo.co.ukwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
but what I was hoping to do was to actually remove the rows from the
server side grid view object, not just refuse to render those rows.
What's the difference...?
Feb 1 '07 #4
On 1 Feb, 19:34, "Mark Rae" <m...@markNOSPAMrae.comwrote:
"Greg" <spammesil...@yahoo.co.ukwrote in message

news:11**********************@v33g2000cwv.googlegr oups.com...
but what I was hoping to do was to actually remove the rows from the
server side grid view object, not just refuse to render those rows.

What's the difference...?
Visually nothing, but if I later want to refer to the server side
gridview object, I don't want to have to remember which rows have been
hidden from the the user.

Unless of course I misunderstood you.... I'm a complete beginner at
web development (I normally do win forms stuff).

Thanks.

Greg.

Feb 1 '07 #5
Greg,

As you have discovered, the GridView control does not allow you to
manipulate rows (unless you put them in the footer or something like
that). What you want to do is create the datasource (ObjectDataSource,
DataSet, etc) programatically where you can manipulate and filter its
contents. I prefer to put this logic in a separate class, but you
could put it in your code-behind class.

Then you bind the customized datasource to the gridview:
grdUsers.DataSource = myDataSource;
grdUsers.DataBind();

Best wishes,
Wesley
>
but what I was hoping to do was to actually remove the rows from the
server side grid view object, not just refuse to render those rows.
What's the difference...?

Visually nothing, but if I later want to refer to the server side
gridview object, I don't want to have to remember which rows have been
hidden from the the user.

Unless of course I misunderstood you.... I'm a complete beginner at
web development (I normally do win forms stuff).

Thanks.

Greg.

Feb 1 '07 #6
"Greg" <sp**********@yahoo.co.ukwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
Visually nothing, but if I later want to refer to the server side
gridview object, I don't want to have to remember which rows have been
hidden from the the user.
Aha...!

Sounds like what you want to do is fetch your underlying data into a
DataSet, create a "view" of that data which you can filter, then bind the
GridView to the filtered view instead of the underlying DataSet, which
remains intact...

using (DataSet MyDataSet = <whatever method you have for creating DataSets)
{
MyDataSet.Tables[0].DefaultView.RowFilter = "FirstName = 'Greg'";
MyGridView.DataSource = MyDataSet.Tables[0].DefaultView;
MyGridView.DataBind();
}
Feb 1 '07 #7
On 1 Feb, 20:26, "Mark Rae" <m...@markNOSPAMrae.comwrote:
"Greg" <spammesil...@yahoo.co.ukwrote in message

news:11**********************@p10g2000cwp.googlegr oups.com...
Visually nothing, but if I later want to refer to the server side
gridview object, I don't want to have to remember which rows have been
hidden from the the user.

Aha...!

Sounds like what you want to do is fetch your underlying data into a
DataSet, create a "view" of that data which you can filter, then bind the
GridView to the filtered view instead of the underlying DataSet, which
remains intact...

using (DataSet MyDataSet = <whatever method you have for creating DataSets)
{
MyDataSet.Tables[0].DefaultView.RowFilter = "FirstName = 'Greg'";
MyGridView.DataSource = MyDataSet.Tables[0].DefaultView;
MyGridView.DataBind();

}
Thanks a lot Wesley and Mark - I'm getting very close now to where I
need to be!

I think the best way to achieve what I want may be to create a
temporary table in the database with the user's edited copy of what
was originally extracted from the table that can't be edited. They
could then edit the contents of the temporary table to their hearts
content, and then when happy, update another table using the contents
of the temporary table. That way I don't have to worry too much about
state. Does that sound like a plan, or over complicating things?

Thanks again,

Greg.

Feb 2 '07 #8
"Greg" <sp**********@yahoo.co.ukwrote in message
news:11*********************@v33g2000cwv.googlegro ups.com...
I think the best way to achieve what I want may be to create a
temporary table in the database with the user's edited copy of what
was originally extracted from the table that can't be edited. They
could then edit the contents of the temporary table to their hearts
content, and then when happy, update another table using the contents
of the temporary table. That way I don't have to worry too much about
state. Does that sound like a plan, or over complicating things?
It's a little difficult to tell as you don't mention why any of this is
necessary...
Feb 2 '07 #9
On 2 Feb, 11:20, "Mark Rae" <m...@markNOSPAMrae.comwrote:
"Greg" <spammesil...@yahoo.co.ukwrote in message

news:11*********************@v33g2000cwv.googlegro ups.com...
I think the best way to achieve what I want may be to create a
temporary table in the database with the user's edited copy of what
was originally extracted from the table that can't be edited. They
could then edit the contents of the temporary table to their hearts
content, and then when happy, update another table using the contents
of the temporary table. That way I don't have to worry too much about
state. Does that sound like a plan, or over complicating things?

It's a little difficult to tell as you don't mention why any of this is
necessary...
Mark,

Yes, I can see why you're not too clear on what I am trying to do. The
requirements can be summarised thus:(NB there is a lot, lot more going
on in the form besides this, but nothing else is relevant)

There are 2 relevant tables in the database, lets call them
masterSchedule and actualSchedule.

When the user clicks on a button, a grid is shown with the contents of
the masterSchedule table. The user can then add to these details or
remove individual details. On pressing a button, the displayed
contents are inserted into the actualSchedule table. The
masterSchedule table is therefore acting as a group of suggestions, or
a template, as to what will eventually be sent to the actualSchedule
table. The masterSchedule table can never be edited by my part of the
application.

Thanks a lot for your time, and I apologise if I didn't explain fully
enough earlier on in the thread!

Greg.


Feb 2 '07 #10
"Greg" <sp**********@yahoo.co.ukwrote in message
news:11*********************@s48g2000cws.googlegro ups.com...
There are 2 relevant tables in the database, lets call them
masterSchedule and actualSchedule.
OK.
The masterSchedule table can never be edited by my part of the
application.
So what's the point of it...? E.g.

1) User fetches a dataset from masterSchedule, makes some changes, and saves
the changes into actualSchedule.

2) masterSchedule is not modified since "The masterSchedule table can never
be edited by my part of the application."

3) User fetches the same dataset from the masterSchedule - aren't they back
where they started...?
Feb 2 '07 #11
On 2 Feb, 11:57, "Mark Rae" <m...@markNOSPAMrae.comwrote:
"Greg" <spammesil...@yahoo.co.ukwrote in message

news:11*********************@s48g2000cws.googlegro ups.com...
There are 2 relevant tables in the database, lets call them
masterSchedule and actualSchedule.

OK.
The masterSchedule table can never be edited by my part of the
application.

So what's the point of it...? E.g.

1) User fetches a dataset from masterSchedule, makes some changes, and saves
the changes into actualSchedule.

2) masterSchedule is not modified since "The masterSchedule table can never
be edited by my part of the application."

3) User fetches the same dataset from the masterSchedule - aren't they back
where they started...?
Absolutely 3.) is a requirement so that they can back to where they
started from at a later date. It may sound bizarre, but this is a
strict customer requirement.

Feb 2 '07 #12

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

Similar topics

0
by: Wannabe | last post by:
I have been trying to figure this out for days now...can someone please help? I am using ASP.Net 2.0 and have a gridview on my page. I have everything working except the delete command. The page...
1
by: =?Utf-8?B?QW1pdA==?= | last post by:
I have an object datasource control that is referencing a class in the app code directory called SQLCommands.vb. That class calls stored procs in a remote server. On my page I'm using a GridView...
2
by: Greg | last post by:
I have a gridview on my form which I have populated using a datareader. What I would like to do is to be able to remove specified records from the gridview, without affecting the source of the...
1
by: Greg | last post by:
I have a gridview on my form which I have populated using a datareader. What I would like to do is to be able to remove specified records from the gridview, without affecting the source of the...
2
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...
2
by: mathewgk80 | last post by:
Hi all, when i try to delete the last row from gridview, i got an exception "Array index out of bound.. When i try to delete some other row, all the rows that follow that row is deleted.. ...
1
by: bJames | last post by:
Hi I've been all around looking for an answer to this question, but can't find it. I've got a gridview with a single unbound column. It's got a textbox and button in the footer row. I"m trying to...
0
by: Andy B | last post by:
I have the following gridview. There are 2 other textBoxes and a button on the page as well. When somebody puts text into the 2 textBoxes and presses the add button, it puts the values of those...
1
by: COHENMARVIN | last post by:
I have a gridview and I need to know the number of rows in it. I find the Page_load and the Gridview_Load events are too early to find out the number of rows. I can use the Gridview_databound...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.