Solved

Shifting gridview columns, doable?

Posted on 2007-03-22
22
714 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
Comment Utility
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
Comment Utility
"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
Comment Utility
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
 
LVL 37

Expert Comment

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

Expert Comment

by:samtran0331
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 37

Expert Comment

by:samtran0331
Comment Utility
>>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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 37

Expert Comment

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

Author Comment

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

Author Comment

by:Camillia
Comment Utility
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
Comment Utility
...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
Comment Utility

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
Comment Utility
>> 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
Comment Utility
let me try it. Thanks for sticking with this.
0
 
LVL 7

Author Comment

by:Camillia
Comment Utility
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
Comment Utility
...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
Comment Utility
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
Comment Utility
i think i will open another question for this as it will get off-topic. I will post the link here .
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now