473,387 Members | 1,844 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,387 software developers and data experts.

Dynamic Bound Columns OnSortCommand not called (Solution)

Alright, I am posting my solution to a problem I've been having. I have
finally found the answer, and it took me a while so I thought I'd
provide the final solution here, since it may be benificial to others
and because I had to search for the solution (not the problem) in order
to find a working one.

I had a datagrid that wasn't sorting, the onsortcommand seemed as
though it wasn't being called, and I had dynamically bound columns in
the page_load sub. That was the big mistake.

Apparently, in order for the sortcommand to work correctly, you need to
bound your columns in a different sub, the page_init event sub. Once
you successfully do this, all is well. After doing a few very specific
searches I found this answer (in a rather vague form) on usenet.

The page_init sub runs before the page_load sub is run, and is only run
once when the page is first loaded, not on every page load.

------------
The code should look like:
Sub Page_Init(Sender As Object, E As EventArgs)
'Don't forget to open a sql connection here, and fill the dataset.

objDataTable = objDataSet.Tables(0)
For i = 0 To objDataTable.Columns.Count - 1
objCol = New BoundColumn()
objCol.HeaderText = objDataTable.Columns(i).ColumnName
objCol.DataField = objDataTable.Columns(i).ColumnName
objCol.SortExpression = objDataTable.Columns(i).ColumnName
DataGrid1.Columns.Add(objCol)
Next

End Sub

Some settings in the datagrid:
AutoGenerateColumns="False"
OnSortCommand="SQLDataGrid_SortCommand"
AllowSorting="True"
------------

Hope this helps anyone out there that is having this problem.

Nov 19 '05 #1
1 1717
Or you could do this:

private page_load()
{
if ( !Page.IsPostBack)
{
//Build Dynamic columns here
}
}

You are only supposed to build (bind) your columns once, not everytime the
page_load event is called.

ENJOY !
"Chad Devine" wrote:
Alright, I am posting my solution to a problem I've been having. I have
finally found the answer, and it took me a while so I thought I'd
provide the final solution here, since it may be benificial to others
and because I had to search for the solution (not the problem) in order
to find a working one.

I had a datagrid that wasn't sorting, the onsortcommand seemed as
though it wasn't being called, and I had dynamically bound columns in
the page_load sub. That was the big mistake.

Apparently, in order for the sortcommand to work correctly, you need to
bound your columns in a different sub, the page_init event sub. Once
you successfully do this, all is well. After doing a few very specific
searches I found this answer (in a rather vague form) on usenet.

The page_init sub runs before the page_load sub is run, and is only run
once when the page is first loaded, not on every page load.

------------
The code should look like:
Sub Page_Init(Sender As Object, E As EventArgs)
'Don't forget to open a sql connection here, and fill the dataset.

objDataTable = objDataSet.Tables(0)
For i = 0 To objDataTable.Columns.Count - 1
objCol = New BoundColumn()
objCol.HeaderText = objDataTable.Columns(i).ColumnName
objCol.DataField = objDataTable.Columns(i).ColumnName
objCol.SortExpression = objDataTable.Columns(i).ColumnName
DataGrid1.Columns.Add(objCol)
Next

End Sub

Some settings in the datagrid:
AutoGenerateColumns="False"
OnSortCommand="SQLDataGrid_SortCommand"
AllowSorting="True"
------------

Hope this helps anyone out there that is having this problem.

Nov 19 '05 #2

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

Similar topics

1
by: Daniel | last post by:
How do I call a delegate in late bound C# dll? there some way to do this w/ a sharedinterface file? any examples? i tried this but it doesnt work: (oType.GetMethod("IOCTLJOB").Invoke(pObj, new...
1
by: J.B | last post by:
I have a datagrid that will display different datasets, (it runs different sprocs based on a value in the querystring) but it will always return 6 columns. The 5th and 6th columns are always Date...
0
by: Julie Barnet | last post by:
I would like to be able to either autogenerate my bound columns or create them at runtime based on parameters passed into the page. When doing either method, I cannot access any of the fields. ...
0
by: Simon | last post by:
I've created several columns at run time and added these to my datagrid using the following: Select Case templateType Case ListItemType.Header lc = New Literal lc.Text = "<B>" & columnName &...
0
by: James | last post by:
I have a DataGrid control. I bind it on the initial loading of the page. It has auto-generated columns, they aren't explicitly defined. On the bind, I'm adding a dropdownlist to every column...
3
by: BartMan | last post by:
Greetings, I have a gridview which is sitting on a multi view control (witin a view), and it is bound to a dataset which I dynamically apply to the control within asp.net page. The problem is...
0
by: pichula | last post by:
I recently started with .NET and C#. I have a stored proc in SQL Server that returns a dynamic/variable set of columns depending on the parameter I pass. I'd like to display the information in a...
0
by: methexandude | last post by:
Hi, I have recently started developing ASP.net applications using VB.net. Well, I created this huge query to retrieve data from SQL Server and create a pivot table, which means I'm creating columns...
3
by: ncsthbell | last post by:
Using MS Access 2007. I have a combo box that is defined with 2 columns. A file sequence number and file name. When you click the down arrow in the combo box, you see both columns. However, when...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.