Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


gridview pagesize value set by web.config not working

Posted on 2011-03-22
Medium Priority
Last Modified: 2012-05-11
I would like to set the gridview pagesize value from a web.config entry.
Web.config has this:
    <add key="pagingSize" value="20" />

Open in new window

gridview has this:
                <asp:GridView ID="gvCustomers1" runat="server" DataSourceID="odsCustomers" 
                    AutoGenerateColumns="False" AllowSorting="True" AllowPaging="True" 
                    EmptyDataText="No data exists" CssClass="siteTable"  
                    DataKeyNames="CustomerID" ViewStateMode="Enabled" 
                    PageSize="<%$  appSettings:pagingSize %>" >

Open in new window

But this is not working.  I get "Int32Converter cannot convert from (null)".  If I hardcode it to 20, it works just fine.

Can you please tell me what I am doing wrong?  Thank you!
Question by:ToolTimeGang
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 16

Accepted Solution

Imran Javed Zia earned 500 total points
ID: 35193819
Hi ,
You can use following code in a method and code to access, make sure you have added related key and value in config appSettings

public static int GetPageSize()
            int pageSize = 20;
                string s = System.Configuration.ConfigurationManager.AppSettings["AppPageSize"];
                pageSize = Convert.ToInt32(s);
            catch { }
            return pageSize;
        int pageSize = GetPageSize();
LVL 16

Assisted Solution

by:Imran Javed Zia
Imran Javed Zia earned 500 total points
ID: 35193840
just change setting  text as
string s = System.Configuration.ConfigurationManager.AppSettings["pagingSize"];

Author Comment

ID: 35193948
Wow!  that was quick.  And it makes sense to me!  so then my setting would be like this:
PageSize=<%= GetPageSize %>

right?  (of course I would first have to add the logic in my code behind)
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

LVL 16

Assisted Solution

by:Imran Javed Zia
Imran Javed Zia earned 500 total points
ID: 35193963
you may use like this
PageSize='<%= GetPageSize() %>'
PageSize='<%= SomeGeneralUtilityClass.GetPageSize() %>'
Please mark it as answered if it is helpful


Author Comment

ID: 35194036
Thanks a bunch!  I'm good now!!!  I sure will mark your answer as helpful!

Author Closing Comment

ID: 35194044
Very speedy with answers.  2nd time today!  That is appreciated so very much!
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 35194048
You are most welcome,

Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question