Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > DataGrids, SortCommands and Microsoft IE WebControl TabStrips Problem

Reply
Thread Tools

DataGrids, SortCommands and Microsoft IE WebControl TabStrips Problem

 
 
Cole Trickle
Guest
Posts: n/a
 
      05-05-2005
Hello, I wonder if anyone has had any experience with this???

I have a page with an IE web control tab strip and a single datagrid. The
datagrid's columns are created manually depending on the SelectedIndex of
the tabstrip.

In order to get the SelectedIndex of the tabstrip I have to wait until the
Page_Load event.
In order to properly initialise the columns so they respond the SortCommand
event I have to use the Page_Init event.

The problem I have is that if I want the events of the column to fire I
can't get the right SelectedIndex (always 0) and if I want to generate the
different columns dependant on SelectedIndex, I get no events firing. I
keep going round in circles...

I have noticed from previous posts that it is suggested I add
<Columns><asp:BoundColumn></asp:BoundColumn></Columns>
the events will fire. They all do except for the SortCommand event. I
experimented and found that adding
<Columns><asp:HyperLinkColumn
SortExpression="Dummy"></asp:HyperLinkColumn></Columns>
will initialise the SortCommand event as well.

Now using the above solves the problem but I was wondering if anyone had
another method as I hate using this sort of workaround in my code.
Cheers


 
Reply With Quote
 
 
 
 
samuelrobertson@gmail.com
Guest
Posts: n/a
 
      05-05-2005
I create DataGrids all the time in page load. The sort column header
control gets a LoadPostData event and thats how the DataGrid control
knows to update its sort column. That's why you have to build the
DataGrid before LoadPostData (and that's why your dummy columns work -
however it is an unstable solution). However, there is an undocumented
LoadPostData2 that occurs immediately after PageLoad, so you should be
able to build the DataGrid at PageLoad and it should grab that event
and update its sort column.

Another possibility is detecting and using the Form.Request variables
directly.

 
Reply With Quote
 
 
 
 
Cole Trickle
Guest
Posts: n/a
 
      05-06-2005
Thanks for your reply Samuel...

I came up with an alternative solution, that seems to work OK. I create all
the columns in the Page_Init event (get all sorting and paging capabilities)
and then in the Page_Prerender event (get the SelectedIndex of the tabstrip)
I remove the columns I don't need prior to binding the data.

<> wrote in message
news: oups.com...
>I create DataGrids all the time in page load. The sort column header
> control gets a LoadPostData event and thats how the DataGrid control
> knows to update its sort column. That's why you have to build the
> DataGrid before LoadPostData (and that's why your dummy columns work -
> however it is an unstable solution). However, there is an undocumented
> LoadPostData2 that occurs immediately after PageLoad, so you should be
> able to build the DataGrid at PageLoad and it should grab that event
> and update its sort column.
>
> Another possibility is detecting and using the Form.Request variables
> directly.
>



 
Reply With Quote
 
Cole Trickle
Guest
Posts: n/a
 
      05-06-2005
I thought I had solved it but was wrong...I'm a bit of a beginner so I'm not
sure I'll be using the correct terminology...Any help is VERY appreciated.

When I initialise all the columns in the Page_Init event the SortCommand
events seem to get 'registered' for all columns. Then I remove the columns I
don't need using the tabstrip's selectedindex property in the Page_Load.

In this instance I have 10 columns, 3 for the first tab, 4 for the second
and 3 for the last tab. So the first tab will only show columns 0-2, second
tab shows columns 3-6 and the last tab shows columns 7-9.

When I navigate to the second tab, extract data I need, bind data to
datagrid and click the sortcommand button the first column in the displayed
datagrid's column collection has a SortExpression of 'y' (this is column 3)
but in the SortCommand event the e.SortExpression is 'x' which is the
SortExpression of column 0 of all 10.

Here is the code with a lot of stuff removed to try and make it clearer...
public class Search : UserInterfaceLayer.LineIntBasePage {
//Control Definitions
protected System.Web.UI.WebControls.DataGrid dgResults;

private void Page_Init(object sender, EventArgs e) {
// Initialise Datagrid
this.InitDataGrids();
}

private void Page_Load(object sender, System.EventArgs e) {
// Remove columns not required for current view...
this.FormatDataGrids();
}

private void Page_PreRender(object sender, EventArgs e) {
if(this.ResultsDataSource != null){
//Now Sort the datagrids
SortGridData((ICollection)this.ResultsDataSource);

// Now bind the data
this.dgResults.DataSource = this.ResultsDataSource; //ResultDataSource
stored in Session
this.dgResults.DataBind();
this.dgResults.Visible = true;
}
}



//Web Form Designer generated code
#region Web Form Designer generated code
override protected void OnInit(EventArgs e) {
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.dgResults.SortCommand += new
System.Web.UI.WebControls.DataGridSortCommandEvent Handler(this.dgResults_SortCommand);
this.Load += new System.EventHandler(this.Page_Load);
this.PreRender += new EventHandler(this.Page_PreRender);
this.Init += new EventHandler(Page_Init);
}
#endregion

//Event Handlers
private void dgResults_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e) {
Trace.Write("SORTCOMMAND", e.SortExpression);
this.SortField = e.SortExpression;
}

/// <summary>
/// Create all the columns required by the DataGrid
/// </summary>
private void InitDataGrids(){
Trace.Write("INITDATAGRIDS", "start of init: column count = " +
this.dgResults.Columns.Count);
// Initialise
HyperLinkColumn hc = null;
this.dgResults.Columns.Clear();

// Set up the columns
// Members
hc = new HyperLinkColumn();
hc.HeaderStyle.ForeColor = Color.White;
hc.HeaderText = "Member ID";
hc.SortExpression = "MemberID";
this.dgResults.Columns.Add(hc);

hc = new HyperLinkColumn();
hc.HeaderText = "Email";
this.dgResults.Columns.Add(hc);

hc = new HyperLinkColumn();
hc.HeaderStyle.ForeColor = Color.White;
hc.HeaderText = "Name";
hc.SortExpression = "Surname";
this.dgResults.Columns.Add(hc);

// Courses
hc = new HyperLinkColumn();
hc.HeaderStyle.ForeColor = Color.White;
hc.HeaderText = "Course Reference";
hc.SortExpression = "CourseReference";
this.dgResults.Columns.Add(hc);

hc = new HyperLinkColumn();
hc.HeaderStyle.ForeColor = Color.White;
hc.HeaderText = "Title";
hc.SortExpression = "Title";
this.dgResults.Columns.Add(hc);

hc = new HyperLinkColumn();
hc.HeaderStyle.ForeColor = Color.White;
hc.HeaderText = "Version";
hc.SortExpression = "Version";
this.dgResults.Columns.Add(hc);

hc = new HyperLinkColumn();
hc.HeaderStyle.ForeColor = Color.White;
hc.HeaderText = "Live";
hc.SortExpression = "Live";
this.dgResults.Columns.Add(hc);

// Course Instances
hc = new HyperLinkColumn();
hc.HeaderStyle.ForeColor = Color.White;
hc.HeaderText = "Course Instance Title";
hc.SortExpression = "CourseTitle";
this.dgResults.Columns.Add(hc);

hc = new HyperLinkColumn();
hc.HeaderStyle.ForeColor = Color.White;
hc.HeaderText = "Tutor";
hc.SortExpression = "Tutor";
this.dgResults.Columns.Add(hc);

hc = new HyperLinkColumn();
hc.HeaderStyle.ForeColor = Color.White;
hc.HeaderText = "Start Date";
hc.SortExpression = "CourseDate";
this.dgResults.Columns.Add(hc);

// Set up the search results pager style
this.dgResults.PagerStyle.Mode = PagerMode.NumericPages;
this.dgResults.PagerStyle.PageButtonCount =
PageHelper.DG_PAGEBUTTONCOUNT;
Trace.Write("INITDATAGRIDS", "end of init: column count = " +
this.dgResults.Columns.Count);
}

/// <summary>
/// Remove the columns that are not
/// required by the currently selected tab
/// </summary>
private void FormatDataGrids(){
const int MEMLOWER = 0; // Lower Column Index Boundary
const int MEMUPPER = 2; // Member Upper Column Index Boundary
const int COURSEUPPER = 6; // Course Upper Column Index Boundary
const int CIUPPER = 9; // Course Instance Upper Column Index Boundary

Trace.Write("FORMAT", this.tbsSearch.SelectedIndex.ToString());
// Set up the columns
switch(this.tbsSearch.SelectedIndex){
case 0: // Members
for(int i = CIUPPER; i > MEMUPPER; i--){
this.dgResults.Columns.RemoveAt(i);
}
break;

case 1: // Courses
for(int i = CIUPPER; i > COURSEUPPER; i--){
this.dgResults.Columns.RemoveAt(i);
}
for(int i = MEMUPPER; i >= MEMLOWER; i--){
this.dgResults.Columns.RemoveAt(i);
}
break;

case 2: // Course Instances
for(int i = COURSEUPPER; i >= MEMLOWER; i--){
this.dgResults.Columns.RemoveAt(i);
}
break;
}
Trace.Write("FORMAT", "end of FormatDataGrids: column count = " +
this.dgResults.Columns.Count + ", sort column 0 = " +
this.dgResults.Columns[0].SortExpression );



}

private void SortGridData(ICollection list) {
Trace.Write("SORTGRIDDATA", this.tbsSearch.SelectedIndex + ", " +
this.SortField);

// Set up the columns
switch(this.tbsSearch.SelectedIndex){
case 0: // Members
// Initialise
MemberCollection.MemberFields sortMem =
MemberCollection.MemberFields.InitValue;

switch(this.SortField) {
case "MemberID":
sortMem = MemberCollection.MemberFields.Id;
break;
case "Surname":
sortMem = MemberCollection.MemberFields.Surname;
break;
}

((MemberCollection)list).Sort(sortMem, this.SortAscending);
break;

case 1: // Courses
// Initialise
CourseCollection.CourseFields sortCo =
CourseCollection.CourseFields.InitValue;

switch(this.SortField){
case "CourseReference":
sortCo = CourseCollection.CourseFields.CourseReference;
break;
case "Title":
sortCo = CourseCollection.CourseFields.Title;
break;
case "Live":
sortCo = CourseCollection.CourseFields.Live;
break;
case "Version":
sortCo = CourseCollection.CourseFields.Version;
break;
}
((CourseCollection)list).Sort(sortCo, this.SortAscending);
break;

case 2: // Course Instances
// Initialise
CourseInstanceCollection.CourseInstanceFields sortCI =
CourseInstanceCollection.CourseInstanceFields.Init Value;

switch(this.SortField){
case "CourseReference":
sortCI =
CourseInstanceCollection.CourseInstanceFields.Cour seReference;
break;
case "CourseTitle":
sortCI =
CourseInstanceCollection.CourseInstanceFields.Cour seTitle;
break;
case "CourseDate":
sortCI =
CourseInstanceCollection.CourseInstanceFields.Cour seDate;
break;
case "Tutor":
sortCI =
CourseInstanceCollection.CourseInstanceFields.Tuto r;
break;
}
((CourseInstanceCollection)list).Sort(sortCI, this.SortAscending);
break;
}
}

#endregion
}


"Cole Trickle" <> wrote in message
news:...
> Thanks for your reply Samuel...
>
> I came up with an alternative solution, that seems to work OK. I create
> all the columns in the Page_Init event (get all sorting and paging
> capabilities) and then in the Page_Prerender event (get the SelectedIndex
> of the tabstrip) I remove the columns I don't need prior to binding the
> data.
>
> <> wrote in message
> news: oups.com...
>>I create DataGrids all the time in page load. The sort column header
>> control gets a LoadPostData event and thats how the DataGrid control
>> knows to update its sort column. That's why you have to build the
>> DataGrid before LoadPostData (and that's why your dummy columns work -
>> however it is an unstable solution). However, there is an undocumented
>> LoadPostData2 that occurs immediately after PageLoad, so you should be
>> able to build the DataGrid at PageLoad and it should grab that event
>> and update its sort column.
>>
>> Another possibility is detecting and using the Form.Request variables
>> directly.
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSE 4 11-15-2006 02:40 AM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola Microsoft Certification 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSD 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd realexxams@yahoo.com Microsoft Certification 0 05-10-2006 02:35 PM
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.public.dotnet.framework.windowsforms,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb Charles A. Lackman ASP .Net 1 12-08-2004 07:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57