|
Home > Archive > Microsoft Content Management Server > February 2005 > Sort postings by custom property
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Sort postings by custom property
|
|
| Mei Ying [MVP] 2005-02-23, 8:46 pm |
| Hi
Not directly. You could iterate through the list of=20
postings and store their custom property values in a=20
DataTable. You can then use a DataView to sort the list in=20
whatever order you like.
Something like this:
PostingCollection pc =3D c.Postings;
//put information about the postings in a table
DataTable dt =3D new DataTable();
=20
dt.Columns.Add("Name",System.Type.GetType
("System.String")); =09
dt.Columns.Add("PromotionStartDate",System.Type.GetType
("System.DateTime"));
=09
DataRow newRow;
for (int i=3D0; i<pc.Count; i++)
{
//add a new row to the table for each posting in=20
the list
newRow =3D dt.NewRow();
//add the name
newRow["Name"] =3D pc[i].Name;
//add the date
newRow["PromotionStartDate"] =3D DateTime.Parse(pc
[i].CustomProperties["PromoDate"].Value);
//add the new row to the table
dt.Rows.Add(newRow);
}
=09
//bind the table to the datagrid
DataView dv =3D dt.DefaultView;
dv.Sort =3D "PromotionStartDate desc";
myDataGrid.DataSource =3D dv;
myDataGrid.DataBind();
regards
Mei Ying
---
Blog: http://meiyinglim.blogspot.com
Book: http://www.packtpub.com/book/mcms
Contact: meiyinglim@hotmail.com
---
>-----Original Message-----
>I have a custom property that as a date value and i wan't=20
to sort postings
>using that property.
>Is possible to order a list of postings using a custom=20
property?
>
>thanks,
>Gon=E7alo Bol=E9o
>
>
>.
>
| |
| Gonçalo Boléo 2005-02-24, 7:51 am |
| I think i couldn't sort directly from custom properties or placeholders.
Your options is an approach i didn't think off.
Thanks.
"Mei Ying [MVP]" <anonymous@discussions.microsoft.com> wrote in message
news:1aec01c51a16$213e9780$a501280a@phx.gbl...
Hi
Not directly. You could iterate through the list of
postings and store their custom property values in a
DataTable. You can then use a DataView to sort the list in
whatever order you like.
Something like this:
PostingCollection pc = c.Postings;
//put information about the postings in a table
DataTable dt = new DataTable();
dt.Columns.Add("Name",System.Type.GetType
("System.String"));
dt.Columns.Add("PromotionStartDate",System.Type.GetType
("System.DateTime"));
DataRow newRow;
for (int i=0; i<pc.Count; i++)
{
//add a new row to the table for each posting in
the list
newRow = dt.NewRow();
//add the name
newRow["Name"] = pc[i].Name;
//add the date
newRow["PromotionStartDate"] = DateTime.Parse(pc
[i].CustomProperties["PromoDate"].Value);
//add the new row to the table
dt.Rows.Add(newRow);
}
//bind the table to the datagrid
DataView dv = dt.DefaultView;
dv.Sort = "PromotionStartDate desc";
myDataGrid.DataSource = dv;
myDataGrid.DataBind();
regards
Mei Ying
---
Blog: http://meiyinglim.blogspot.com
Book: http://www.packtpub.com/book/mcms
Contact: meiyinglim@hotmail.com
---
>-----Original Message-----
>I have a custom property that as a date value and i wan't
to sort postings
>using that property.
>Is possible to order a list of postings using a custom
property?
>
>thanks,
>Gonçalo Boléo
>
>
>.
>
|
|
|
|
|