Solved

Shifting gridview columns, doable?

Posted on 2007-03-22
22
723 Views
Last Modified: 2012-06-21
We have a Windows application, done in proprieroty software. It has something like a gridview/datagrid rows/colmns of data on a screen. It has 10 columns: Name, ID, Address, phone#, etc.

If user searches by Name, the first column displayed is name. If use Searches by phone#, first columns is shown is Phone etc.

*** the key for the grid row will always be the ID

Is this doable in ASP.Net's gridview??
0
Comment
Question by:Camillia
  • 12
  • 10
22 Comments
 
LVL 37

Expert Comment

by:samtran0331
ID: 18773573
the short answer is yes, it is doable with a Gridview.

But there are a few different ways to implement it.

The easier ways to "shift columns" is to just leave the Gridview with autogeneratecolumns=true
and then change the underlying datasource, datatable or dataview...
0
 
LVL 7

Author Comment

by:Camillia
ID: 18773605
"then change the underlying datasource, datatable or dataview..." not sure what u mean by that...

I'm calling a stored proc...coulmns are  ID, Name, Phone, ...

Have different Stored procs with different combinations of columns (i dont think u meant that)...

OR grab the data in a datatable, dataset something and shift columns like that?

Let me ask you this...u think I should even do that? I need a good reason (maybe performance)  to tell my manager why i dont want to do it this way ( i want to keep my coding simple but of course i cant tell him that :) )
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 18773739
have a look at this:
http://msdn2.microsoft.com/en-us/library/ms752213.aspx
scroll to the section: "User Interactions with a GridView"
"Users can reorder columns in a GridView by pressing the left mouse button while it is over a column header and then dragging that column to a new position. While the user drags the column header, a floating version of the header is displayed as well as a solid black line that shows where to insert the column.

If you want to modify the default style for the floating version of a header, specify a ControlTemplate for a GridViewColumnHeader type that is triggered when the Role property is set to Floating. For more information, see How to: Create a Style for a Dragged GridView Column Header."

my current project, we're using the telerik grid so I can't test right now...but that's really interesing...
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 37

Expert Comment

by:samtran0331
ID: 18773754
...oh wait...that's probably talking about winform isn't it?
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 18773774
speaking of telerik, have a look at this:
http://www.telerik.com/demos/aspnet/Grid/Examples/Programming/WebMail/DefaultCS.aspx

the example allows you to drag/drop columns to re-order them
0
 
LVL 7

Author Comment

by:Camillia
ID: 18773805
I did come across that link and thought it was for web. I cant use any third party tools...

 ex-developer did it in .Net 1.1 and datagrid. Have to get a copy of his code but his code is really crappy...
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 18773876
>>grab the data in a datatable, dataset something and shift columns like that?
That's what I was thinking.

>>Have different Stored procs with different combinations of columns
no, I wasn't thinking different sproc's, but you can have a conditional "if" statements in one stored procedure to execute different selects...this is the cheesiest way to accomplish the "column shift"...but also the quickest...so your sproc would have another variable like @sortcolumn

and the sproc becomes something like:
if @sortcolumn="name"
select name, address,ph...etc
end
if @sortcolumn="address"
select address,name,ph
end



0
 
LVL 7

Author Comment

by:Camillia
ID: 18774444
let me think about your first method. I will open a new question if my manager doesnt agree with  the "non-shifting" of columns.
0
 
LVL 7

Author Comment

by:Camillia
ID: 18780310
crap, my manager wants shifting columns...

let me ask you this... suppose i have 5 columns. The first column is ID and it is the "key" to the gridview...i mean...the column that will have the hyperlink which user can click on....

can I have more than one column with hyperlink? i dont think i can...so when I shift, i have to remove the hyperlink from the shifted column??
0
 
LVL 7

Author Comment

by:Camillia
ID: 18780642
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 18781447
>>suppose i have 5 columns. The first column is ID and it is the "key" to the gridview...i
>>mean...the column that will have the hyperlink which user can click on....
>>can I have more than one column with hyperlink? i dont think i can...so when I shift, i
>>have to remove the hyperlink from the shifted column

when the user clicks the hyperlink, what happens?
you can use a "select" column that never shifts and make that your hyperlink column that always appears first...and then the rest of the columns shift after
it depends what you're doing with the hyperlink, and in some instances, you can make all the columns hyperlinks that do the same thing
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 18781507
>>maybe with that example.
yes, that's in line with what I was thinking...
0
 
LVL 7

Author Comment

by:Camillia
ID: 18782035
thanks. So it's dynamic building of the gridview.
0
 
LVL 7

Author Comment

by:Camillia
ID: 18782117
But is it really worth it? I think users/my managet should understand that some functionality will be different in a web app than in a winform app done in a proprietory software...

If i do dynamic, then sorting/paging will be dynamic too...right? just too much hassle...

any performance issues with doing it dynamic?
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 18782181
...that tutorial is manipulating the gridview columns...but you can see it's working closely and relying on the datatable that will eventually bind the gridview...so what I was originally thinking is manipulating the datatable and then leaving the gridview to bind to the datatable with autogeneratecolumns=true
**after** creating the datatable...

...realisitically, it doesn't really matter...the "shift" logic is the same...just where do you want to do it? in the sql, the datatable, or in the gridview....

how do you know which column the user is searching?
0
 
LVL 7

Author Comment

by:Camillia
ID: 18782240

For searching, I have a "where" clause that i build in the code behind but you're right...i can have combinations of searches..for example, user can choose NAME and Account...then what should the first column be?? I think it's just stupid that they want this like winform app... in that app, users cant do combination searches...it's either search by name OR search by Account OR search by whatever...

 I can change my manager's mind only if I can tell him it will affect performace :)  If i use dynamic gridview, then i have to dynamically localize the headers as well, paging too, sorting too...right?
0
 
LVL 37

Accepted Solution

by:
samtran0331 earned 500 total points
ID: 18782604
>> I can change my manager's mind only if I can tell him it will affect performace :)  If i use dynamic gridview, then i have to dynamically localize the headers as well, paging too, sorting too...right?

That's why earlier somewhere I recommended you do it in the stored procedure and then let gridview autogeneratecolumns=true...manipulating it in code means more work....

here's what I would recommend to get this done (with minimal effort) =D

1. have a textbox for search criteria
2. have  a dropdownlist for what field to search
3. let the gridview autogeneratecolumns=true
4. and then your sproc becomes something like this (this is using Northwind):

DECLARE
@PrimaryColumn varchar(25),
@SearchValue varchar(25)

------------Test values:------------------
SELECT @PrimaryColumn = 'CompanyName'
SELECT @SearchValue = 'Antonio'
------------------------------------------

IF @PrimaryColumn = 'CompanyName'
BEGIN
      SELECT CompanyName,ContactName,ContactTitle
      FROM Customers
      WHERE CompanyName LIKE '%'+@SearchValue+'%'
END

IF @PrimaryColumn = 'ContactName'
BEGIN
      SELECT ContactName,CompanyName,ContactTitle
      FROM Customers
      WHERE ContactName LIKE '%'+@SearchValue+'%'
END

IF @PrimaryColumn = 'ContactTitle'
BEGIN
      SELECT ContactTitle ,ContactName,CompanyName
      FROM Customers
      WHERE ContactTitle LIKE '%'+@SearchValue+'%'
END

the @PrimaryColumn value receives the dropdownlist for what field to put first
and the @SearchValue is what your user types in

if you play with the above query in QueryAnalyser and set the 2 params to one of the different columns...you'll see it works...

so once the data comes back from the sproc, the gridview will have "shifted" the columns...
0
 
LVL 7

Author Comment

by:Camillia
ID: 18782622
let me try it. Thanks for sticking with this.
0
 
LVL 7

Author Comment

by:Camillia
ID: 18783629
your solution does away with the combination search. User has to choose the field they want to search on. For example, if they cant select NAME and ACCOUNT. In case of combination search, i guess we need to make an assumption and say...ok...display NAME first...

i've presented the solution/options to my manager. He needs to decide if he want the shifting column or combination search.
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 18788136
...sure...in the "search column" dropdownlist, have a "search all"....and then add to the sproc to search all columns....and leave the column orde alone...

or...you can still get slick with the stored procedure....and shift the columns based on which column returns the search criteria...

the sproc would have to do a count of each column searched first....
...but a "search all" could still be done and returned all from one stored proc...
0
 
LVL 7

Author Comment

by:Camillia
ID: 18788478
ah, yeah, very good idea...

I think one issue i see is this: since I'm shifting columns, I think all columns have to be hyperlinked. I will hide the "id" behind all the columns as my key...

Now, user searches by NAME, this will be the first column, this will be hyperlink. BUT, I dont want the rest of the columns to be hyperlinked now. (The vendor windows-app only makes the first-searched-by-column hyperlinked)....

how can I  **un-hyperlink** the rest of the columns??
0
 
LVL 7

Author Comment

by:Camillia
ID: 18789959
i think i will open another question for this as it will get off-topic. I will post the link here .
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question