Solved

gridview pagesize value set by web.config not working

Posted on 2011-03-22
7
1,607 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
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;
            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
ID: 35193840
just change setting  text as
string s = System.Configuration.ConfigurationManager.AppSettings["pagingSize"];
0
 

Author Comment

by:ToolTimeGang
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)
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 16

Assisted Solution

by:Imran Javed Zia
Imran Javed Zia earned 125 total points
ID: 35193963
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
ID: 35194036
Thanks a bunch!  I'm good now!!!  I sure will mark your answer as helpful!
0
 

Author Closing Comment

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

Expert Comment

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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
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 …
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

828 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