'asp.net gridview in update panel, make visible and update content

Currently, I have a dynamically created gridview on my page. When a user enters something in a textbox and presses a button, the whole page refreshes to populate the gridview and make it visible. I do not want that anymore. How would I go about using the UpdatePanel to make the gridview visible and populate it?

<div class="span-93 prepend-2 top">
        <strong>Enter  Number</strong><br />
        <asp:TextBox ID="PartNumber" runat="server" Width="100"></asp:TextBox>
        <asp:Button ID="CreateButton" runat="server" Width="85" Text="Locate" OnClick="CreateButton_Click" />
    </div>
<asp:Label ID="Select" runat="server" Font-Bold="true" Text="Select choice" Visible="false"></asp:Label><br />
            <ajax:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:GridView ID="GridView" Visible="false" runat="server"  HeaderStyle-Width="200" HeaderStyle-BackColor="#2B6292" HeaderStyle-ForeColor="White" 
                    AllowSorting="true" AllowPaging="true" Width="600" AutoGenerateColumns="False" OnRowCreated="GridView_OnRowCreated" 
                    DataKeyNames="Id" onsorting="GridView_OnSort">
                        <Columns>
                            ...
                        </Columns>
                    </asp:GridView>
                </ContentTemplate>
                <Triggers>
                    <ajax:AsyncPostBackTrigger ControlID="CreateButton"/>
                </Triggers>
            </ajax:UpdatePanel>

Theres another button on the page called CreateButton, obviously, that will populate the gridview and make it visible so a user can select from it. Is this possible? Thanks in advance.

Edit: Binding Code to gridview:

    protected void Create_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Number.Text))
            {
                BLL newbll = new BLL();
                Database.DataTable tempTable = newbll.GetItemByPartNumber(Number.Text);

                if (Table.Count != 0)
                {
                DataTable table = tempTable ;

                string[] VID = { "Id" };
                GridviewDiv.Visible = true;
                GridView.DataSource = table;
                GridView.DataKeyNames = VID;
                GridView.DataBind();
            }
        }
    }


Solution 1:[1]

Since your update panel's update mode is set to Conditional, in your code behind after your call to DataBind on the grid view, you will need to call Update() on the name of your Update Panel (named UpdatePanel in this instance).

Solution 2:[2]

Having declared the CreateButton as a trigger you shouldn't have to explicitly call Update() to do the refresh

Where have you declared the CreateButton ? - it must be in the same 'NamingContainer' as the UpdatePanel for it to be found

Can you move the declaration of the CreateButton inside your update panel. If so you do not need to explicitly declare a trigger - see if that makes a difference

Solution 3:[3]

Use the following

<asp:UpdatePanel ID="..." runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">       
    <ContentTemplate>
      <asp:GridView  ....>
      </asp:GridView .....>

    ///buttons ..............whatever

    </ContentTemplate>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lance Harper
Solution 2 Tom Carter
Solution 3