473,324 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Setting SortExpression programmatically

Hi!

When I add a bound column programatically, like:

BoundColumn bc = new BoundColumn();
bc.DataField = "myField";
bc.SortExpression = "myField";
myGrid.Columns.Add(bc);

the SortCommand event does not trig at all!

If I replace the code whith the markup syntax in the ascx file, it works
fine. I've google around but the only solution to the problem seemes to be
moving the code to Page_Init.

This is not possible because at that time I dont know the structure of the
table. Depending on a selection in a dropdown, i get diffrent datatables to
bind with the grid. The selectedindexchanged event on the dropdown will not
fire until much later in execution, so in Page_Init I wouldn't know what was
selected yet. Furthermore i cant understand what Page_Init has to do with all
of this.

I'm confused, any ideas?

Thanks,
Paul

Nov 19 '05 #1
4 2477
My suggestion would be, add the bound column in page_init event. And, later
on whenever you want, like in ItemBound event, use FindControl to get the
current ListItem and if the type of the control found is BoundColumn, assign
proper sort expressions, etc.,

I think this is right approach, if you've problems
do post here.

Regards
Vadivel Kumar
http://blogs.wdevs.com/varahe

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:56**********************************@microsof t.com...
Hi!

When I add a bound column programatically, like:

BoundColumn bc = new BoundColumn();
bc.DataField = "myField";
bc.SortExpression = "myField";
myGrid.Columns.Add(bc);

the SortCommand event does not trig at all!

If I replace the code whith the markup syntax in the ascx file, it works
fine. I've google around but the only solution to the problem seemes to be
moving the code to Page_Init.

This is not possible because at that time I dont know the structure of the
table. Depending on a selection in a dropdown, i get diffrent datatables to bind with the grid. The selectedindexchanged event on the dropdown will not fire until much later in execution, so in Page_Init I wouldn't know what was selected yet. Furthermore i cant understand what Page_Init has to do with all of this.

I'm confused, any ideas?

Thanks,
Paul

Nov 19 '05 #2
Hi,

What is the order in which controls are placed ?
If I understand this correctly, you have a custom control (similar to
datagrid) & a dropdown.
The dropdown has list of fields that you allow the user to sort on.
Depending upon user selection, you wish to sort the grid on the
selected column & show it to user

Correct ?
If yes, place the grid control beneath the dropdown. Set the SortField
in grid's initialization event (or some event which fires before the
grid is rendered)

Does this help ?

Kalpesh

Nov 19 '05 #3
Hi and thanks for answering!

With your suggestion I’ll probably get one step closer, but unfortunately
not all the way. One problem remains, I don’t even know how many bound
columns the table will have. I get different data tables to bind with
depending on the selection in the drop down, and there’s no way I can predict
the column structure of the table.

I also did a simple check with a new blank web project. When I change
selection in a dropdown (autopostback=true), the events fire in the following
order:

Page_Init
Page_Load
DropDownList1_Load
DataGrid1_Load
DropDownList1_SelectedIndexChanged (This is where I create columns and bind
the grid)
Page_PreRender
DropDownList1_PreRender
DataGrid1_PreRender

Thanks again,
Paul

"Vadivel Kumar" wrote:
My suggestion would be, add the bound column in page_init event. And, later
on whenever you want, like in ItemBound event, use FindControl to get the
current ListItem and if the type of the control found is BoundColumn, assign
proper sort expressions, etc.,

I think this is right approach, if you've problems
do post here.

Regards
Vadivel Kumar
http://blogs.wdevs.com/varahe

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:56**********************************@microsof t.com...
Hi!

When I add a bound column programatically, like:

BoundColumn bc = new BoundColumn();
bc.DataField = "myField";
bc.SortExpression = "myField";
myGrid.Columns.Add(bc);

the SortCommand event does not trig at all!

If I replace the code whith the markup syntax in the ascx file, it works
fine. I've google around but the only solution to the problem seemes to be
moving the code to Page_Init.

This is not possible because at that time I dont know the structure of the
table. Depending on a selection in a dropdown, i get diffrent datatables

to
bind with the grid. The selectedindexchanged event on the dropdown will

not
fire until much later in execution, so in Page_Init I wouldn't know what

was
selected yet. Furthermore i cant understand what Page_Init has to do with

all
of this.

I'm confused, any ideas?

Thanks,
Paul


Nov 19 '05 #4
Hi,

Can you explain the scenario exactly ?
This will help understand it better

Kalpesh

Nov 19 '05 #5

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

Similar topics

11
by: Zlatko Matiæ | last post by:
Hello. I have a MS Access front-end working with PostgreSQL database. I have successfully created saved File DSN. My paa-through queries are referring to that file as well as linked tables. But I...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
2
by: Philipp Sumi | last post by:
Hello I have to start an Asp.net project that involves i18n, so I was doing some reading on the subject. I'm not sure (and I *really* hope I'm wrong) but is it true, that there is no way to...
0
by: Mo | last post by:
Hi, I'm getting an error: Input string was not in a correct format This happens when I try to sort a column. It seems that the sort event handler claims that the sort expression is not in...
1
by: fuchs.markus | last post by:
Hello, on my page, I have a DetailsViewControl connected to a SqlDataSource. Now when I dynamically set the FilterExpression and FilterParameters - for example in a OnClick-EventHandler of a...
0
by: Northern | last post by:
Hello, I have some trouble to declare and instantiate dynamically an ObjectDataSource in the codebehind file. The idea is to bind the objectdatasource to a gridview and have automate sorting and...
4
by: Tomasz | last post by:
Hello Developers, Here is interesting problem I just came across: how do I wire a GridView control programmatically? Here is my sample code using Object Data Source: protected void...
0
by: miketayloruk | last post by:
I'm using a detailsview control that I want to use to insert data to a table. One of the fields is a date field and I want that to default to todays date. In classic asp I would do it like this: ...
7
by: ThePope78705 | last post by:
Hi all, I have a web form that is generated on the fly. I need to insert some javascript into the form to do validation on the contents of each text box when the text box loses focus. here is what I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.