avul-OS-unda
avul-OS-unda

Reputation: 167

ASP.NET Grid View not updating inside an update panel

Background: Trying to avoid the complete post back and use partial post back to refresh the data grid. I have checked MSDN, and stack overflow and tried different combinations of the control values for triggering the post back but no luck.

Code

 <asp:ScriptManager ID="sm1" runat="server" EnablePartialRendering="true" />
    <div>
        <asp:UpdatePanel ID="upTest" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" >
            <ContentTemplate>
                <asp:GridView ID="gvTest" runat="server" Visible="true" ShowHeader="true" AutoGenerateColumns="false">
                    <Columns>
                         <asp:TemplateField>
                        <HeaderTemplate>
                            <div>Document Type</div>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="txtDescription" Style="margin: 2px" MaxLength="254" Text='<%# Bind("DocName") %>' runat="server" Width="200px" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <br />
                <label>
                    <AjaxControlToolkit:AsyncFileUpload ID="AsyncFileUpload1" Width="400px" runat="server"
                        OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />
                </label>
                <label id="lblStatus"></label>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

Code behind

 if (AsyncFileUpload1.HasFile)
    {
        string strPath = MapPath("~/Uploads/") + Path.GetFileName(e.filename);
        AsyncFileUpload1.SaveAs(strPath);
        SetGridData(1);
        upTest.Update();
    }

    private void SetGridData(int count)
{
    List<Document> Documents = new List<Document>();
    Document doc = new Document();
    doc.DocName = "test doc";
    for (int i = 0; i < count; i++)
    {
        Documents.Add(doc);
    }
    gvTest.DataSource = Documents;
    gvTest.DataBind();
}

On Page_Load the Grid is loaded with 5 data rows and on the async post back the grid is reset to one data row. While looking at the chrome debugger, I can see the grid data is coming from the server on both Page_Load (5 rows) and async load( 1 data row). But the data grid is not refreshed. I do call the grid.DataBind() during the async post back. Anyone has any ideas whats going on? Am I missing something?

Note: Everything works with normal ASP.Net controls, just dont work with AJAX file upload control

Upvotes: 1

Views: 2752

Answers (2)

Ronnie Kapoor
Ronnie Kapoor

Reputation: 133

try UpdateMode="Always" . it will work

Upvotes: 0

Sam
Sam

Reputation: 2917

Are you calling the DataBind() method of your GridView within SetGridData? And also add a AsyncPostBackTrigger

Have a look at an example here

Upvotes: 1

Related Questions