473,856 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Use rs;
this.DataGrid1. DataBind();

Everything works fine and when the page is loaded, the datagrid displays
the list of users present in the Usermanager.Use rs 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.Use rs)
{
if(user.Privile ges.Contains(ce rtainPrivilege) ||
user.Privileges .Contains(anoth erCertainPrivil ege)
{
//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 3654
Hi CGue,

Hi , unfortunally the DataGridItemCol lection 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.ne t> wrote in message
news:%2******** ********@TK2MSF TNGP09.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.Use rs;
this.DataGrid1. DataBind();

Everything works fine and when the page is loaded, the datagrid displays the list of users present in the Usermanager.Use rs 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.Use rs)
{
if(user.Privile ges.Contains(ce rtainPrivilege) ||
user.Privileges .Contains(anoth erCertainPrivil ege)
{
//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.ne t> wrote in message
news:%2******** ********@TK2MSF TNGP09.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.Use rs;
this.DataGrid1. DataBind();

Everything works fine and when the page is loaded, the datagrid displays the list of users present in the Usermanager.Use rs 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.Use rs)
{
if(user.Privile ges.Contains(ce rtainPrivilege) ||
user.Privileges .Contains(anoth erCertainPrivil ege)
{
//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 programmaticall y 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_auth or_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_autho r_plug>
----------------------------------------------

"CGuy" <cg**@csharp.ne t> wrote in message
news:#I******** ******@TK2MSFTN GP09.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.Use rs;
this.DataGrid1. DataBind();

Everything works fine and when the page is loaded, the datagrid displays the list of users present in the Usermanager.Use rs 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.Use rs)
{
if(user.Privile ges.Contains(ce rtainPrivilege) ||
user.Privileges .Contains(anoth erCertainPrivil ege)
{
//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 "Manipulati ng 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.ne t> wrote in message
news:#I******** ******@TK2MSFTN GP09.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.Use rs;
this.DataGrid1. DataBind();

Everything works fine and when the page is loaded, the datagrid displays the list of users present in the Usermanager.Use rs 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.Use rs)
{
if(user.Privile ges.Contains(ce rtainPrivilege) ||
user.Privileges .Contains(anoth erCertainPrivil ege)
{
//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
2672
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
1346
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 instance on the central instance host and the database instance on the on the database instance host. I got a few response, which is highly appriciable and I respect for those SAP gurus in order to providing me the valuable inputs. But if some...
4
1328
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
1779
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") %>' > .... .... </asp:TemplateColumn> but with no success.
2
1372
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 for First/Surname. How do I use Databinding and yet say "if theres nothing in Company, show Firstname/Surname, otherwise show Company". Any ideas on this?!
0
1200
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 frames and all).when i run it its running fine.but when i just now check in the vs.net design mode inside the other aspx file(serverMain), where i inserted it on the left then i see this error: 'dgversion_itemDataBound' is not a member of...
1
1647
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
1639
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 fragment htat I have written. But it is giving a "Expression Syntax" Error. #include <stdio.h> #include <conio.h> main() { int p, n, z, num, term, i, res ; p = n = z = 0; printf("Enter how many numbers you require? ");
0
1016
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 a specific category link) The issue is this page works fine when it is a separate page but when I try to include this to my Master page, the content page does not display. The Values are passed correctly as I can see it in the URL but, a small...
0
11063
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10699
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
10390
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9535
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...
0
7098
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
5762
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
5960
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4580
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3203
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.