473,626 Members | 3,467 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET Dynamic Gridview Question

I have a number of simple select queries that a user needs to be able to
execute and display the data on the screen in a gridview. My thought was
that I could use a Gridview set to dymanically generate columns and bound to
a SQLDataSource. Then the user can click buttons (or whatever) and it
changes the SelectCommand property of the SQLDataSource and re-binds the
GridView.

That worked great until I enabled paging. When paging is clicked, it always
reverts back to the default SelectCommand that's embeded with the control.

Any thoughts on what I can do to make this work?
Mar 23 '06 #1
4 7336
Have you tried using the GridView.Filter Expression propety rather than
changing the SelectCommand, this will do what you want, it uses the syntax

GridView.Filter Expression = "FieldName = Value";

You can also add parameters by using the GridView.Filter Parameters collection.

Below is some code from a page that i have written that updates the
datasource of a GridView based on which option is selected in a DropDownList
control.

ControlParamete r cprViewState = new ControlParamete r();
cprViewState.Co ntrolID = ddlSelectView.I D.ToString();
cprViewState.Pr opertyName = "SelectedValue" ;
cprViewState.Na me = "ViewState" ;
cprViewState.Ty pe = TypeCode.Int32;
SqlDataSource1. FilterExpressio n = "Status = {0}";
SqlDataSource1. FilterParameter s.Add(cprViewSt ate);

the {0} in the filter expression represents the first item in the
FilterParameter s collection. {1}, {2} etc would work for the second and
third items etc.

"Bishop" wrote:
I have a number of simple select queries that a user needs to be able to
execute and display the data on the screen in a gridview. My thought was
that I could use a Gridview set to dymanically generate columns and bound to
a SQLDataSource. Then the user can click buttons (or whatever) and it
changes the SelectCommand property of the SQLDataSource and re-binds the
GridView.

That worked great until I enabled paging. When paging is clicked, it always
reverts back to the default SelectCommand that's embeded with the control.

Any thoughts on what I can do to make this work?

Mar 23 '06 #2
I had not looked into that yet. When looking at it for the sqlDataSource it
looks like it's good for changing parts of the query such as the where
clause but in this case I need to change the entire query. Although it will
always be a select query, the fields I choose and the table I query could be
entirly different.
"clickon" <cl*****@discus sions.microsoft .com> wrote in message
news:1B******** *************** ***********@mic rosoft.com...
Have you tried using the GridView.Filter Expression propety rather than
changing the SelectCommand, this will do what you want, it uses the syntax

GridView.Filter Expression = "FieldName = Value";

You can also add parameters by using the GridView.Filter Parameters
collection.

Below is some code from a page that i have written that updates the
datasource of a GridView based on which option is selected in a
DropDownList
control.

ControlParamete r cprViewState = new ControlParamete r();
cprViewState.Co ntrolID = ddlSelectView.I D.ToString();
cprViewState.Pr opertyName = "SelectedValue" ;
cprViewState.Na me = "ViewState" ;
cprViewState.Ty pe = TypeCode.Int32;
SqlDataSource1. FilterExpressio n = "Status = {0}";
SqlDataSource1. FilterParameter s.Add(cprViewSt ate);

the {0} in the filter expression represents the first item in the
FilterParameter s collection. {1}, {2} etc would work for the second and
third items etc.

"Bishop" wrote:
I have a number of simple select queries that a user needs to be able to
execute and display the data on the screen in a gridview. My thought was
that I could use a Gridview set to dymanically generate columns and bound
to
a SQLDataSource. Then the user can click buttons (or whatever) and it
changes the SelectCommand property of the SQLDataSource and re-binds the
GridView.

That worked great until I enabled paging. When paging is clicked, it
always
reverts back to the default SelectCommand that's embeded with the
control.

Any thoughts on what I can do to make this work?

Mar 23 '06 #3
I found one solution that looks like it might work. Set a session variable
to the current select string, then in the form load event set the
SelectCommand to the current select string. It seems to work but isn't the
most elegent. Any other ideas on this?

"Bishop" <no****@nospam. com> wrote in message
news:e3******** ********@TK2MSF TNGP12.phx.gbl. ..
I had not looked into that yet. When looking at it for the sqlDataSource
it looks like it's good for changing parts of the query such as the where
clause but in this case I need to change the entire query. Although it
will always be a select query, the fields I choose and the table I query
could be entirly different.
"clickon" <cl*****@discus sions.microsoft .com> wrote in message
news:1B******** *************** ***********@mic rosoft.com...
Have you tried using the GridView.Filter Expression propety rather than
changing the SelectCommand, this will do what you want, it uses the
syntax

GridView.Filter Expression = "FieldName = Value";

You can also add parameters by using the GridView.Filter Parameters
collection.

Below is some code from a page that i have written that updates the
datasource of a GridView based on which option is selected in a
DropDownList
control.

ControlParamete r cprViewState = new ControlParamete r();
cprViewState.Co ntrolID = ddlSelectView.I D.ToString();
cprViewState.Pr opertyName = "SelectedValue" ;
cprViewState.Na me = "ViewState" ;
cprViewState.Ty pe = TypeCode.Int32;
SqlDataSource1. FilterExpressio n = "Status = {0}";
SqlDataSource1. FilterParameter s.Add(cprViewSt ate);

the {0} in the filter expression represents the first item in the
FilterParameter s collection. {1}, {2} etc would work for the second and
third items etc.

"Bishop" wrote:
I have a number of simple select queries that a user needs to be able to
execute and display the data on the screen in a gridview. My thought
was
that I could use a Gridview set to dymanically generate columns and
bound to
a SQLDataSource. Then the user can click buttons (or whatever) and it
changes the SelectCommand property of the SQLDataSource and re-binds the
GridView.

That worked great until I enabled paging. When paging is clicked, it
always
reverts back to the default SelectCommand that's embeded with the
control.

Any thoughts on what I can do to make this work?


Mar 24 '06 #4
sunrei
1 New Member
Bishop,

Let me know if you find another solution. I'm having the same problem and because I'm building the select statement based on the user selection of a form. Depending on the options selected, I may be querying different database tables. For now, I'm going to try to implement the solution you suggested using session variables.

Regards,
Apr 21 '06 #5

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

Similar topics

4
5033
by: Larry Grady | last post by:
Anyone up for a challenge? I've been struggling with this for a few days and was hoping someone could help me. Pouring through all the messageboards I just can't find the solution. We have a GridView that needs to be dynamically designed, depending on what collection of fields our uses want to edit for their product data. We have 400+ fields of information per product so they're selecting a subset of those fields to edit.
3
13735
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should always confirm a delete action. There is also a consensus that the best way to do this is a template...
0
2378
by: K B | last post by:
PLEASE be patient and read this. I believe I've actually reached the end of the Web trying to find the answer! I have an aspx using a MasterPage with a ContentPlaceholder. I have a datatable that I use to dynamically populate a gridview - I have to do this in order to specify which control type to put in one of the columns. All this works fine. I've run Trace and can clearly see that the control.id I assigned (lblQuestionID) is there...
4
8321
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the date column always shows the date and time while I just want the short date. I have tried applying a format string {0:d} but to no avail. I saw a lot of posts regarding the htmlencode property but I do not know how to turn that off for a...
7
2322
by: =?Utf-8?B?SmVmZiBCZWVt?= | last post by:
The default paging behavior of the gridview doesn't work well with very large sets of data which means we have to implement some sort of custom paging. The examples I have seen (4guysfromrolla, etc.) suggest using an ObjectDataSource which has built-in paging functionality that, when used in conjunction with certain SQL 2005 functionality, only works with the records to be displayed on the page rather than the entire set. The problem with...
1
2615
by: =?Utf-8?B?cGVsZWdrMQ==?= | last post by:
i have a GridView which i can Page on (go to page 2,10,...) the thing is that i have a dynamic query which set the GridView from starts on page 1. the thing is that when i start to go over the pages - the dynamic query isnt saved and i cant go to the real page 4 for example of the dynamic query,rather i go to page 4 of the original basic query
1
2780
by: jimmysjams | last post by:
I'm modifying someone else's code and I have hit a snag. I don't want to rewrite what's already there but I might have to. I have a gridview, in the gridview is a set number of columns that will always be there. On the end of the gridview I need to add columns dynamically. These columns may or may not exist and I don't know how many there will be. The way it is currently programmed, there are 2 gridviews, one for viewing a list and...
0
1262
by: Craig Buchanan | last post by:
I am adding templates to a gridview dynamically. these columns are based on data values that are generated prior to calling the gridviews databind. the challenge is when the form does a postback. i need to recreate these templates. until now, i've been storing the data needed to create the dynamic columns in a session variable. i was hoping to use the viewstate, but the viewstate isn't loaded until page_load. the gridview's templates...
14
15058
by: agamoto | last post by:
hello guys, i don't know if this is the right tread to post but i have the following problem: i've built a dynamic gridview in run time because the gried values (columns, headers, etc) are conditioned with values that come from the database. I used TemplateField's to do that. i don't have a active connection to the database. i store my information to a dataset and bind it to the gridview another thing is that all rows in m gridview are...
0
8268
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
8202
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8707
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...
1
8366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8510
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...
1
6125
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
4093
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...
1
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1512
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.