Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6048945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:31:13+00:00 2026-05-23T07:31:13+00:00

I have one button and one gridview in my asp.net web page.I give the

  • 0

I have one button and one gridview in my asp.net web page.I give the following code in c# code behind file

protected void Button1_Click1(object sender, EventArgs e)
{

    string t = @"<countries>
            <country>
            <name>ANGOLA</name><code>1</code><size>1345 amp</size>
            </country>
            <country>
            <name>ANGOLA</name><code>2</code><size>1345 amp</size>
            </country>
            <country>
            <name>ANGOLA</name><code>3</code><size>1345 amp</size>
            </country>
            <country>
            <name>ANGOLA</name><code>4</code><size>1345 amp</size>
            </country>
            <country>
            <name>ANGOLA</name><code>5</code><size>1345 amp</size>
            </country>
            <country>
            <name>ANGOLA</name><code>6</code><size>1345 amp</size>
            </country>
            <country>
            <name>ANGOLA</name><code>24</code><size>1345 amp</size>
            </country>
            <country>
            <name>ANGOLA</name><code>24</code><size>1345 amp</size>
            </country>
            <country>
            <name>ANGOLA</name><code>24</code><size>1345 amp</size>
            </country>
            <country>
            <name>ANGOLA</name><code>24</code><size>1345 amp</size>
            </country>
            <country>
            <name>ANGOLA</name><code>24</code><size>1345 amp</size>
            </country>
            <country>
            <name>ANGOLA</name><code>24</code><size>1345 amp</size>
            </country>
            <country>
            <name>ANGOLA</name><code>24</code><size>1345 amp</size>
            </country>
            <country>
            <name>ANGOLA</name><code>24</code><size>1345 amp</size>
            </country>

            <country>
            <name>BENIN</name><code>204</code><size>435 amp</size>
            </country>
            </countries>";
    //string bgtFocusCmd = "<bgfocuscmd >";
    //string countCmd = "<count name='" + Session["operation"] + "'customerid='" + customerid.Text + "' breakup='" + breakup + "' date='" + DateFrom.Text + "' >";
    //bgtFocusCmd += countCmd + "</bgfocuscmd>";
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(t);
    DataSet resultData = new DataSet();
    resultData.ReadXml(new StringReader(doc.OuterXml));
    dataGrid.DataSource = resultData.Tables[0].DefaultView;
    dataGrid.DataBind();

}

and in aspx page

<asp:GridView ID="dataGrid" runat="server"  
        AllowPaging="True" 
        AutoGenerateColumns="True" 
        CellPadding="4" 
        DataSourceID="Button1_Click1.t"
        EmptyDataText="NO data available."
        EnableSortingAndPagingCallbacks="true" 
        ForeColor="#333333" 
        GridLines="None"  
        Height="302px"
        HorizontalAlign="Left" 
        PageSize="2" 
        RowStyle-Width="20" 
        Width="560px"
        OnPageIndexChanged="Button1_Click1">
    <RowStyle BackColor="#EFF3FB" />                    
    <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#2461BF" />
    <AlternatingRowStyle BackColor="White" />
</asp:GridView>

When i click the button1 it will display the gridview with two rows.
But when i click the pagenumbers in the grid view like to click page number 2 it will display no data available . I want to display that page in the grid view. Can anyone tell how to do this it will really appreciated.
Thank you

When

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:31:13+00:00Added an answer on May 23, 2026 at 7:31 am

    You need to add a state to remeber the last data that you like to show, and not make databind on page change, just give the data. Try this.

    const string cRemStateNameConst = "cRemState_cnst";
    
    public int cRemState
    {
        set
        {
            if (value == -1)
                ViewState.Remove(cRemStateNameConst);
            else
                ViewState[cRemStateNameConst] = value;
        }
        get
        {
            if (ViewState[cRemStateNameConst] is int)
                return (int)ViewState[cRemStateNameConst];
            else
                return -1;
        }
    }
    
    
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if(cRemState == 1)
            GetTheData();
    }
    
    protected void Button1_Click1(object sender, EventArgs e)
    {
        cRemState = 1;
        GetTheData();
        dataGrid.DataBind();
    }
    
    void GetTheData()
    {
        string t = @"<countries>
                <country>
                <name>ANGOLA</name><code>1</code><size>1345 amp</size>
                </country>
                <country>
                <name>ANGOLA</name><code>2</code><size>1345 amp</size>
                </country>
                <country>
                <name>ANGOLA</name><code>3</code><size>1345 amp</size>
                </country>
                <country>
                <name>ANGOLA</name><code>4</code><size>1345 amp</size>
                </country>
                <country>
                <name>ANGOLA</name><code>5</code><size>1345 amp</size>
                </country>
                <country>
                <name>ANGOLA</name><code>6</code><size>1345 amp</size>
                </country>
                <country>
                <name>ANGOLA</name><code>24</code><size>1345 amp</size>
                </country>
                <country>
                <name>ANGOLA</name><code>24</code><size>1345 amp</size>
                </country>
                <country>
                <name>ANGOLA</name><code>24</code><size>1345 amp</size>
                </country>
                <country>
                <name>ANGOLA</name><code>24</code><size>1345 amp</size>
                </country>
                <country>
                <name>ANGOLA</name><code>24</code><size>1345 amp</size>
                </country>
                <country>
                <name>ANGOLA</name><code>24</code><size>1345 amp</size>
                </country>
                <country>
                <name>ANGOLA</name><code>24</code><size>1345 amp</size>
                </country>
                <country>
                <name>ANGOLA</name><code>24</code><size>1345 amp</size>
                </country>
    
                <country>
                <name>BENIN</name><code>204</code><size>435 amp</size>
                </country>
                </countries>";
        //string bgtFocusCmd = "<bgfocuscmd >";
        //string countCmd = "<count name='" + Session["operation"] + "'customerid='" + customerid.Text + "' breakup='" + breakup + "' date='" + DateFrom.Text + "' >";
        //bgtFocusCmd += countCmd + "</bgfocuscmd>";
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(t);
        DataSet resultData = new DataSet();
        resultData.ReadXml(new StringReader(doc.OuterXml));
        dataGrid.DataSource = resultData.Tables[0].DefaultView;
    
    }
    

    What I have made here. I have add a viewstate to rember the last data that you like to show. So after the button pressed, and then the page pressed, page remeber to call again the same data, but with out databing, on pageload, so page will change. One think left to do, is to reset the pager if the user press again your button.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to insert an event to the aspx.cs page. I have one asp:button and
I have a delete button in each row of GridView (component ASP.NET). I want
In my web application (asp.net & vb code), I had two different gridview. Each
I've got a ASP.NET 3.5 sp1 site, and on one page I have two
I have a Gridview, a label and a Button in ASP.net. If the total
I have the following asp.net code, the user has to select a row with
I have a gridview where one column is an Add / Remove asp:button which
In my code I have one textbox and one button. Whatever place you type
I have an asp.net intranet site hosted on IIS on my computer. On one
I have an ASP.NET GridView that has four columns. The first three are typical

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.