Solved

gridview pagesize value set by web.config not working

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

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!
0
Comment
Question by:ToolTimeGang
  • 4
  • 3
7 Comments
 
LVL 16

Accepted Solution

by:
Imran Javed Zia earned 125 total points
Comment Utility
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;
            try
            {
                string s = System.Configuration.ConfigurationManager.AppSettings["AppPageSize"];
                pageSize = Convert.ToInt32(s);
            }
            catch { }
            return pageSize;
        }
        int pageSize = GetPageSize();
0
 
LVL 16

Assisted Solution

by:Imran Javed Zia
Imran Javed Zia earned 125 total points
Comment Utility
just change setting  text as
string s = System.Configuration.ConfigurationManager.AppSettings["pagingSize"];
0
 

Author Comment

by:ToolTimeGang
Comment Utility
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)
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 16

Assisted Solution

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


0
 

Author Comment

by:ToolTimeGang
Comment Utility
Thanks a bunch!  I'm good now!!!  I sure will mark your answer as helpful!
0
 

Author Closing Comment

by:ToolTimeGang
Comment Utility
Very speedy with answers.  2nd time today!  That is appreciated so very much!
0
 
LVL 16

Expert Comment

by:Imran Javed Zia
Comment Utility
You are most welcome,
Thanks
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now