PC Review


Reply
Thread Tools Rate Thread

DataView Sort

 
 
Bill Burris
Guest
Posts: n/a
 
      30th Jun 2003
In the following piece of code from my control, the Sort doesn't work. The
foreach processes the data in the order that it appears in the XML file.

protected override void Render(HtmlTextWriter output)
{
_XmlPath = Page.Request.MapPath( @"content\" + _XmlFileName );
_ds.ReadXml( _XmlPath );
DataView dv = _ds.Tables[0].DefaultView;
dv.Sort = "PagePosition ASC";
foreach( DataRow r in dv.Table.Rows )
{
output.Write( "<hr width='100' color='maroon' SIZE='1'
align='middle'>" );
RenderBook( output, r );
}
output.Write( "<hr width='100' color='maroon' SIZE='1'
align='middle'>" );
}

If I put the following code on a WebForm, the data is sorted properly, but
only 14 rows are displayed, not the whole table.

private void Page_Load(object sender, System.EventArgs e)
{
string XmlPath = Page.Request.MapPath( @"content\csbooks.xml" );
DataSet ds = new DataSet();
ds.ReadXml( XmlPath );
DataView dv = ds.Tables[0].DefaultView;
dv.Sort = "PagePosition ASC";
Repeater1.DataSource = dv;
Repeater1.DataBind();
}

Any ideas for what is going wrong in these 2 pieces of code? In the first
piece of code the sort doesn't work. In the second piece of code only 14
rows are displayed by the Repeater, when there should be 27.

thanks

Bill
--
http://www.componentsnotebook.com/


 
Reply With Quote
 
 
 
 
Bill Burris
Guest
Posts: n/a
 
      30th Jun 2003
"Al Cadalzo" <(E-Mail Removed)> wrote in message
news:%23vwf%(E-Mail Removed)...
> iterate through the data view like so:
>
> foreach(DataRowView drv in dv)
> {
> DataRow r = drv.Row();
> ....
>
> }


Thanks Al, that is just what I needed.

I kept looking in the documentation and my books to find something in
DataView. If I had just looked into DataView.Item, I would have discovered
the DataRowView class. All the books I have give examples using DataBind to
bind to a control, but as you see in my second question I also had problems
with that.

The second question: Any ideas for why the Repeater only displays the first
14 rows?

thanks

Bill
--
http://www.componentsnotebook.com/

> "Bill Burris" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > private void Page_Load(object sender, System.EventArgs e)
> > {
> > string XmlPath = Page.Request.MapPath( @"content\csbooks.xml" );
> > DataSet ds = new DataSet();
> > ds.ReadXml( XmlPath );
> > DataView dv = ds.Tables[0].DefaultView;
> > dv.Sort = "PagePosition ASC";
> > Repeater1.DataSource = dv;
> > Repeater1.DataBind();
> > }
> >



 
Reply With Quote
 
Al Cadalzo
Guest
Posts: n/a
 
      30th Jun 2003
Bill,

Put a breakpoint on the DataBind() statement and then examine dv.Count. Is
it = 27?


"Bill Burris" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Al Cadalzo" <(E-Mail Removed)> wrote in message
> news:%23vwf%(E-Mail Removed)...
> > iterate through the data view like so:
> >
> > foreach(DataRowView drv in dv)
> > {
> > DataRow r = drv.Row();
> > ....
> >
> > }

>
> Thanks Al, that is just what I needed.
>
> I kept looking in the documentation and my books to find something in
> DataView. If I had just looked into DataView.Item, I would have

discovered
> the DataRowView class. All the books I have give examples using DataBind

to
> bind to a control, but as you see in my second question I also had

problems
> with that.
>
> The second question: Any ideas for why the Repeater only displays the

first
> 14 rows?
>
> thanks
>
> Bill
> --
> http://www.componentsnotebook.com/
>
> > "Bill Burris" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > >
> > > private void Page_Load(object sender, System.EventArgs e)
> > > {
> > > string XmlPath = Page.Request.MapPath( @"content\csbooks.xml" );
> > > DataSet ds = new DataSet();
> > > ds.ReadXml( XmlPath );
> > > DataView dv = ds.Tables[0].DefaultView;
> > > dv.Sort = "PagePosition ASC";
> > > Repeater1.DataSource = dv;
> > > Repeater1.DataBind();
> > > }
> > >

>
>



 
Reply With Quote
 
Al Cadalzo
Guest
Posts: n/a
 
      30th Jun 2003
Bill,

Since the number of items you're seeing is about half of the total, I'm
wondering if it might have something to do with AlternatingItemTemplate?
Are you specifying both an ItemTemplate and an AlternatingItemTemplate?

Al

"Bill Burris" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In the following piece of code from my control, the Sort doesn't work.

The
> foreach processes the data in the order that it appears in the XML file.
>
> protected override void Render(HtmlTextWriter output)
> {
> _XmlPath = Page.Request.MapPath( @"content\" + _XmlFileName );
> _ds.ReadXml( _XmlPath );
> DataView dv = _ds.Tables[0].DefaultView;
> dv.Sort = "PagePosition ASC";
> foreach( DataRow r in dv.Table.Rows )
> {
> output.Write( "<hr width='100' color='maroon' SIZE='1'
> align='middle'>" );
> RenderBook( output, r );
> }
> output.Write( "<hr width='100' color='maroon' SIZE='1'
> align='middle'>" );
> }
>
> If I put the following code on a WebForm, the data is sorted properly, but
> only 14 rows are displayed, not the whole table.
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> string XmlPath = Page.Request.MapPath( @"content\csbooks.xml" );
> DataSet ds = new DataSet();
> ds.ReadXml( XmlPath );
> DataView dv = ds.Tables[0].DefaultView;
> dv.Sort = "PagePosition ASC";
> Repeater1.DataSource = dv;
> Repeater1.DataBind();
> }
>
> Any ideas for what is going wrong in these 2 pieces of code? In the first
> piece of code the sort doesn't work. In the second piece of code only 14
> rows are displayed by the Repeater, when there should be 27.
>
> thanks
>
> Bill
> --
> http://www.componentsnotebook.com/
>
>



 
Reply With Quote
 
Bill Burris
Guest
Posts: n/a
 
      1st Jul 2003
Thanks Al

> Are you specifying both an ItemTemplate and an AlternatingItemTemplate?


That's what the problem was. My AlternatingItemTemplate was just putting an
<hr> between each row. By deleting the AlternatingItemTemplate and putting
the <hr> at the end of the ItemTemplate solved the problem.

Bill
--
http://www.componentsnotebook.com/


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Dataview sort Cindy Lee Microsoft C# .NET 2 12th Jan 2007 09:21 PM
DataView.Sort NaN gilly3 Microsoft C# .NET 3 20th Mar 2006 07:29 PM
Dataview will not sort Raymond Lewallen Microsoft VB .NET 9 8th Nov 2004 09:18 PM
Re: DataView Sort William Ryan eMVP Microsoft ADO .NET 0 30th Jul 2004 12:04 AM
DataView sort fails to sort on fields with comma in field names Mone Hsieh Microsoft ADO .NET 1 14th May 2004 10:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:47 PM.