473,785 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Difficult Sorting Situation in Datagrid

I have a Datagrid using the Edit/Update mode to alter data in the
datasource.

I needed to have a bit more flexible interface in the editmode with a design
that couldn't work in the columns. So I fixed this by only having ONE
template column (plus the edit button column) and then have html tables in
both the header and the edit items to have complete control over the design.
This works fine.
Now my boss wants Sorting in the column headers... and since therer are only
ONE column I can't use the sorting function of the datagrid...

How do I make these headers of my own to trigger the sort event in the grid
and also send the right argumnents?

best regards
/Lars Netzel
Nov 19 '05 #1
2 1317
hi Lars,
you could create your own linkbuttons with commandname="So rt" and
commandArgument ="ColumnName " in your header column.
here is a sample bindGrid function that takes in a sort (and a filter)
to apply to the datasource.

private void bindGrid(string rowFilter, string sort)
{
int ID = Int32.Parse(thi s.ddlMeatPlants .SelectedItem.V alue);
DataSet ds = null;
try
{
ds = new DB.Producers(). SelectByMeatPla nt(ID);
}
catch(Exception ex)
{
this.lblResult. Text = ex.Message;
return;
}
this.dv.Table = ds.Tables[0];
this.dv.Sort = sort;
dv.RowFilter = rowFilter;
if(dv.Count > 0)
{
this.DataGrid1. Visible = true;
this.DataGrid1. DataSource = dv;
this.DataGrid1. DataBind();
}
}

in the Page_Load, you can call it with empty strings for the sort and
filter parameters. in the event handler for your sort linkbuttons, you
can pass in the commandArgument as the sort parameter.
i haven't tried this, but i think it should work.
tim

Nov 19 '05 #2
Hi Lars,

You can assign SortExpression for the template column, e.g. "specialSor t".
Then in DataGrid_SortCo mmand event

if (e.SortExpressi on.Equals("spec ialSort"))
{
// special sorting
}
else
{
// normal sorting
}

HTH

Elton Wang
el********@hotm ail.com

"Lars Netzel" wrote:
I have a Datagrid using the Edit/Update mode to alter data in the
datasource.

I needed to have a bit more flexible interface in the editmode with a design
that couldn't work in the columns. So I fixed this by only having ONE
template column (plus the edit button column) and then have html tables in
both the header and the edit items to have complete control over the design.
This works fine.
Now my boss wants Sorting in the column headers... and since therer are only
ONE column I can't use the sorting function of the datagrid...

How do I make these headers of my own to trigger the sort event in the grid
and also send the right argumnents?

best regards
/Lars Netzel

Nov 19 '05 #3

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

Similar topics

54
17436
by: Spammay Blockay | last post by:
I've been tasked with doing technical interviews at my company, and I have generally ask a range of OO, Java, and "good programming technique" concepts. However, one of my favorite exercises I give interviewees seems to trip them up all the time, and I wonder if I'm being too much of a hardass... it seems easy enough to ME, but these guys, when I get them up to the whiteboard, seem to get really confused. The exercise is this:
12
2392
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that field... This grid displayes results based on users search.. public static int numberDiv; private void Page_Load(object sender, System.EventArgs e) {
0
1645
by: Chris Mayers | last post by:
I have a Windows Forms DataGrid that has a DataView as a datasource. My problem is that I want the datagrid to exhibit some special sorting properties when the header rows are clicked on. From reading round the newsgroups, it seems that a custom 'IComparer' is the answer, but I'm not quite sure how to do this. Really, how to get at the IComparer that the DataGrid/DataView uses for sorting. Can anyone point me towards a nice example...
2
945
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child datagrid. HTML Datagrid1 TemplateColumn Table Header information Detail Information
3
3127
by: melanieab | last post by:
Hi, I'm programatically sorting in a datagrid. When a column header is clicked, the sort happens twice for some reason, making it looks like it only sorts in descending order. I can tell it sorts twice because I inserted a messagebox in the dgMouse (MouseUp) event. Before ok is pressed, the table changes from the order it was loaded to ascending order. After ok is pressed, it goes to descending. The code is below. Any idea why...
5
2534
by: DKC | last post by:
Hi, Using VB.NET. I have a datagrid having a strongly typed array of objects as its data source. The data from the array of objects is displayed by means of a table style, which is fine, but I cannot sort the data when I click on the column header. I have set the tablestype.allowsorting = true, but this has no effect.
8
15170
by: simchajoy2000 | last post by:
I thought the only thing I had to do to disable column sorting in VB.NET was to set datagrid.AllowSorting = False. Unfortunately this has never worked for me. I discovered another set of code that seems to work for 99% of the cases where I need to disable datagrid column sorting: Private Sub datagrid_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles datagrid.MouseDown Dim pt As New Point(e.X,...
0
2092
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any help........pls urgent ========================================================= <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm3.aspx.vb" Inherits="TestDatagrids.WebForm3"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">...
0
2582
by: Scott | last post by:
Hello all and thanks in advance for any help you may be able to offer me. I am quite new to asp.net and am trying to work with a datagrid but am having some problems with it. Here's the problem... My datagrid displays 2 columns of checkboxes and allows the user to select the check boxes and sort the datagrid. My first problem, if
0
9646
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
9483
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
10346
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
9956
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
8982
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
5386
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
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
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.