473,405 Members | 2,185 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,405 software developers and data experts.

excluding some rows when databinding

Hi,

Say I have an Array of "Person" objects that I'm using as the DataSource for
a grid control. At databinding time I'd like to select only people with
age>18 to go into the grid and ignore all the others.

The only way I can think is to make a new array (or arraylist) containing
only those I want to display but this seems a bit cumbersome. Is there any
simple way to do this (for example in the ItemDataBound event)?

I guess I could write a custom enumerator but that sounds like even more
work than copying the array.

TIA

Andy
Nov 19 '05 #1
1 1701
You can handle the DataGrid's RowDatabound event and do something like this:

private void _grid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs
e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
if (((Person)e.Item.DataItem).Age > 18)
{
e.Item.Visible = false;
}
}
}

e.Item is the DataGridRow in the DataGrid. e.Item.DataItem is the row/object
that it was data bound to -- Person in your case. So inspect the Person object
then set the DataGridRow's Visible to false.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

Say I have an Array of "Person" objects that I'm using as the
DataSource for a grid control. At databinding time I'd like to select
only people with
age>> 18 to go into the grid and ignore all the others.
age>> The only way I can think is to make a new array (or arraylist)
containing only those I want to display but this seems a bit
cumbersome. Is there any simple way to do this (for example in the
ItemDataBound event)?

I guess I could write a custom enumerator but that sounds like even
more work than copying the array.

TIA

Andy


Nov 19 '05 #2

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

Similar topics

2
by: Niklas Ringdahl | last post by:
Hello. I am using databindings to bind my dataset to comboboxes, textboxes and labels. Some of my UI depends on knowing when the user changes the values, but I have some problems knowing when my...
2
by: dhnriverside | last post by:
Hi I'm using a Metabuilders checked list box to create a list of contacts on my page. Each contact has a FirstName, Surname, and Company. Except that some might not have an entry for Company, or...
2
by: Andy Fish | last post by:
Hi, First some background: When you databind a repeater control, the controls within the template are given an id like Repeater1:_ctl<n>:Button1 where <n> increments for each repeater item. If...
6
by: Nathan Sokalski | last post by:
I am using a DataSet as the DataSource of a DataList in my code. The SQL used to get the data from the database begins with: SELECT...
1
by: Nathan Sokalski | last post by:
When I run my application, which uses databinding in a DataList, I recieve the following error: Server Error in '/' Application. ...
12
by: weeodett | last post by:
Is there a way to automate the deletion of the oldest rows in a transaction log file when the file reaches a certain number of rows? Currently, we are simply deleting the oldest rows manually every...
7
Shashi Sadasivan
by: Shashi Sadasivan | last post by:
Hi, I have a table with no rows for the moment. table name = mytable rows = id, id1, qty id and id1 together is the primary key when i try tthe following select sum(qty) from mytable where id...
9
by: moondaddy | last post by:
using c# 3.5 I have list of business objects which I will use in lists for databinding and I want to hide some of the fields so they don't show up in the list control. some of my list will be:...
1
by: gordon57 | last post by:
Hi everybody, i'm doing a query where i want retrieve some records when i do the query without 'limit' the result returns me the correct number of rows, but when i use limit the result returns me the...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
Oralloy
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,...
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,...

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.