Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a property of a control programatically

Status
Not open for further replies.

jgd1234567

Programmer
May 2, 2007
68
GB
Hi, maybe i'm just being picky/lazy but i'm trying to set the PageSize of my DataPager (which sits within the LayoutTemplate of my ListView). I tried doing:

PageSize="<%# Globals.Settings.Content.News.MaximumRows %>"

and i received no errors but it simply ignored it. I thought the databinding syntax should work fine because i am using it from within a template. If i do:

((DataPager)lvwNews.FindControl("pager")).PageSize = Globals.Settings.Content.News.MaximumRows

from within the Page_Load of my page it works fine but i still don't understand why my first approach did not work. Appreciate if you could help. Thanks
 
try one of these variations:
PageSize='<%# Globals.Settings.Content.News.MaximumRows %>'
PageSize='<%= Globals.Settings.Content.News.MaximumRows %>'
PageSize='<%# Globals.Settings.Content.News.MaximumRows.ToString() %>'
PageSize='<%= Globals.Settings.Content.News.MaximumRows.ToString() %>'

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi, none of the above work:

PageSize='<%# Globals.Settings.Content.News.MaximumRows %>' - runs but is simply ignored

PageSize='<%= Globals.Settings.Content.News.MaximumRows %>' - error "Cannot create an object of type 'System.Int32' from its string representation '<%= Globals.Settings.Content.News.MaximumRows %>' for the 'PageSize' property."

PageSize='<%# Globals.Settings.Content.News.MaximumRows.ToString() %>' - error "Cannot convert type 'string' to 'int'"

PageSize='<%= Globals.Settings.Content.News.MaximumRows.ToString() %>' - error "Cannot create an object of type 'System.Int32' from its string representation '<%= Globals.Settings.Content.News.MaximumRows.ToString() %>' for the 'PageSize' property."

I must be missing something completely because everything looks fine to me in the first example.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top