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

Urgent Help Required from Gurus - Conditional databinding

Hi,

I have an ASPX page which has a datagrid and this datagrid is bound to a
Custom Collection.

sample code

this.DataGrid1.DataSource = UserManager.Users;
this.DataGrid1.DataBind();

Everything works fine and when the page is loaded, the datagrid displays
the list of users present in the Usermanager.Users object.

Now, I want to do a conditional binding - for example, I want the
datagrid to have only those users who have certain privileges. To be more
specific, this is what I want to do

foreach(User user in UserManager.Users)
{
if(user.Privileges.Contains(certainPrivilege) ||
user.Privileges.Contains(anotherCertainPrivilege)
{
//Add the row to the grid
}
else
{
//Do not add this row to the grid
}
}

How do I accomplish this - please note that I don't want to the change the
datasource of the grid to reflect this - the data source should be the
entire list of Users and not a filtered list based on priviliges.

Please help me with this - what I am looking for is a solution which will
allow me to use the ItemDataBound or DataBinding events to do this.

Also, I do not want to hide the rows (visible = false). This spoils the
paging routines in the page.

CGuy
Jul 21 '05 #1
4 3602
Hi CGue,

Hi , unfortunally the DataGridItemCollection does not provide any method
to add or delete items, therefore you cannot add or remove rows in the grid.

I would strongly suggest you that the best way to do this is filtering the
data source and bind the grid to the filtered collection. if you don't want
to do this for some weird reason then the only alternative that I see is
customize the datagrid class by yourself, this is by far more complex , and
pointless in this case, that filtering a collection.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"CGuy" <cg**@csharp.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I have an ASPX page which has a datagrid and this datagrid is bound to a Custom Collection.

sample code

this.DataGrid1.DataSource = UserManager.Users;
this.DataGrid1.DataBind();

Everything works fine and when the page is loaded, the datagrid displays the list of users present in the Usermanager.Users object.

Now, I want to do a conditional binding - for example, I want the
datagrid to have only those users who have certain privileges. To be more
specific, this is what I want to do

foreach(User user in UserManager.Users)
{
if(user.Privileges.Contains(certainPrivilege) ||
user.Privileges.Contains(anotherCertainPrivilege)
{
//Add the row to the grid
}
else
{
//Do not add this row to the grid
}
}

How do I accomplish this - please note that I don't want to the change the
datasource of the grid to reflect this - the data source should be the
entire list of Users and not a filtered list based on priviliges.

Please help me with this - what I am looking for is a solution which will
allow me to use the ItemDataBound or DataBinding events to do this.

Also, I do not want to hide the rows (visible = false). This spoils the
paging routines in the page.

CGuy

Jul 21 '05 #2
Use a Datagrid.Table["yourtable"].select (kinda simalar to a SQL select)
statement to populate a DataRow array. You can then point your datagrid to
that as your datasource.

"CGuy" <cg**@csharp.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I have an ASPX page which has a datagrid and this datagrid is bound to a Custom Collection.

sample code

this.DataGrid1.DataSource = UserManager.Users;
this.DataGrid1.DataBind();

Everything works fine and when the page is loaded, the datagrid displays the list of users present in the Usermanager.Users object.

Now, I want to do a conditional binding - for example, I want the
datagrid to have only those users who have certain privileges. To be more
specific, this is what I want to do

foreach(User user in UserManager.Users)
{
if(user.Privileges.Contains(certainPrivilege) ||
user.Privileges.Contains(anotherCertainPrivilege)
{
//Add the row to the grid
}
else
{
//Do not add this row to the grid
}
}

How do I accomplish this - please note that I don't want to the change the
datasource of the grid to reflect this - the data source should be the
entire list of Users and not a filtered list based on priviliges.

Please help me with this - what I am looking for is a solution which will
allow me to use the ItemDataBound or DataBinding events to do this.

Also, I do not want to hide the rows (visible = false). This spoils the
paging routines in the page.

CGuy

Jul 21 '05 #3
You cannot programmatically add to or remove elements from the Items
collection, which is a collection that is created at the time of
databinding. The best you can do is manipulate the data in the ItemCreated
event which gives you access to this bound collection - even if you set the
data to contain nothing the entry will still exist, and a grid position
would likely still occur. At the stage of ItemDataBound the actual
DataBinding has occured so in reality its already too late to do what you
want.

What you could probably do is provide a dataview of the data in the dataset
and have that filter out what you dont want to bind, and then bind it - this
is called a row filter and is probably more akin to what you require.
Alternatively, take your dataset and clone a new dataset manually at runtime
from the origonal dataset, and bind to that instead.

I would suggsetd you have a read of this:
http://msdn.microsoft.com/msdnmag/is...g/default.aspx

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
----------------------------------------------

"CGuy" <cg**@csharp.net> wrote in message
news:#I**************@TK2MSFTNGP09.phx.gbl...
Hi,

I have an ASPX page which has a datagrid and this datagrid is bound to a Custom Collection.

sample code

this.DataGrid1.DataSource = UserManager.Users;
this.DataGrid1.DataBind();

Everything works fine and when the page is loaded, the datagrid displays the list of users present in the Usermanager.Users object.

Now, I want to do a conditional binding - for example, I want the
datagrid to have only those users who have certain privileges. To be more
specific, this is what I want to do

foreach(User user in UserManager.Users)
{
if(user.Privileges.Contains(certainPrivilege) ||
user.Privileges.Contains(anotherCertainPrivilege)
{
//Add the row to the grid
}
else
{
//Do not add this row to the grid
}
}

How do I accomplish this - please note that I don't want to the change the
datasource of the grid to reflect this - the data source should be the
entire list of Users and not a filtered list based on priviliges.

Please help me with this - what I am looking for is a solution which will
allow me to use the ItemDataBound or DataBinding events to do this.

Also, I do not want to hide the rows (visible = false). This spoils the
paging routines in the page.

CGuy

Jul 21 '05 #4
Check out "Manipulating DataSource Values while binding to DataGrid" section
in this article,
http://www.microsoft.com/india/msdn/...rQuestions.asp
x?

--
Saravana
Microsoft India Community Star,MC**
www.extremeexperts.com

"CGuy" <cg**@csharp.net> wrote in message
news:#I**************@TK2MSFTNGP09.phx.gbl...
Hi,

I have an ASPX page which has a datagrid and this datagrid is bound to a Custom Collection.

sample code

this.DataGrid1.DataSource = UserManager.Users;
this.DataGrid1.DataBind();

Everything works fine and when the page is loaded, the datagrid displays the list of users present in the Usermanager.Users object.

Now, I want to do a conditional binding - for example, I want the
datagrid to have only those users who have certain privileges. To be more
specific, this is what I want to do

foreach(User user in UserManager.Users)
{
if(user.Privileges.Contains(certainPrivilege) ||
user.Privileges.Contains(anotherCertainPrivilege)
{
//Add the row to the grid
}
else
{
//Do not add this row to the grid
}
}

How do I accomplish this - please note that I don't want to the change the
datasource of the grid to reflect this - the data source should be the
entire list of Users and not a filtered list based on priviliges.

Please help me with this - what I am looking for is a solution which will
allow me to use the ItemDataBound or DataBinding events to do this.

Also, I do not want to hide the rows (visible = false). This spoils the
paging routines in the page.

CGuy

Jul 21 '05 #5

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

Similar topics

2
by: VBer | last post by:
Hi, It's getting urgent. Need some VB6 starting code to read newsgroup headers for a Newsreader app I'm working on. Anything will do: Winsock, CDO, Internet Transfer Control? etc. Thanks.
3
by: mike_basis | last post by:
Hi All, >From last 2 weeks I am despirately trying to get the installation steps of R/3 4.7 on SQL server 2000 on Windows 2k or 2003 server. This is for a distributed environment, I mean central...
4
by: CGuy | last post by:
Hi, I have an ASPX page which has a datagrid and this datagrid is bound to a Custom Collection. sample code this.DataGrid1.DataSource = UserManager.Users; this.DataGrid1.DataBind();
2
by: The Colonel | last post by:
I'd like to dynamically turn off a whole column if I can. I can use Visible=False, but would like to do this in code. I tried <asp:TemplateColumn Visible='<%= IsAllowed("delete") %>' > .......
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...
0
by: samir dsf | last post by:
hi i thinks its a very strange problem.I had been running my file ServerList2.aspx and i see the output(when i do f5). i am using this file serverList2.aspx on hte left side of a main page (using...
1
by: SpiderSwamy | last post by:
Hi, I know little bit about asp, I am facing a problem in Validating the ASP Form.. Example: Stud ID: 501242016 FirstName: Ajit LastName: Kar
1
by: frontloader | last post by:
Freinds, I want some of you to help me write a program in 'C' to count the Total no. of +ves, total no of -ves and total no of zeros using ternary (Conditional Operaators). I am enclosing the Code...
0
by: mrpage | last post by:
I have developed a page that uses a ASP.Datalist control to display details including images in a database. The page uses parameters passed by links from the home page (i.e, category ID when clicking...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
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,...

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.