1
votes

My gridview is inside an updatepanel, the gridview is not showing the updated data for some reason. Am i missing something? my code looks like the other examples i have found.

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateSelectButton="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" ColumnName="test" CssClass="auto-style14" EnableViewState="false" Font-Size="Medium" HorizontalAlign="Left" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="1010px">
                    <Columns>
                        <asp:ButtonField Text="Details" />
                    </Columns>
                    <FooterStyle BackColor="White" ForeColor="#000066" />
                    <HeaderStyle BackColor="#006699" BorderStyle="Solid" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle" />
                    <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                    <RowStyle ForeColor="#000066" />
                    <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#007DBB" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#00547E" />
                    <RowStyle HorizontalAlign="Center" />
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>

CS:

        }
        GridView1.DataSource = visualDataTable;
        GridView1.DataBind();
        UpdatePanel1.Update();
    }
1
This looks correct. The only reason I can think of why it wouldn't show anything is if your visualDataTable is empty. - dvo
What happens if you remove the UpdatePanel? - VDWWD
Visualdatatable is not empty, if I refresh the webpage the gridview updates.. - Jake Mogensen
You're going to need to create a minimal reproducible example. It needs to be more minimal (we don't need to see all your styling settings) and more Verifiable (you need to include enough parts to reproduce the issue, such as relevant Page_Load calls etc). - mason
Are you updating GridView on a Button Click? - Jawad Anwar

1 Answers

0
votes

First of all, you need to set AutoPostBack="true" for you GridView and you should provide Triggers in UpdatePanel that'll update your GridView on a specific event, like in the following example:

<Triggers>
     <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="SelectedIndexChanged" />
</Triggers>

Whenever this event will occur it'll update your GridView. Or In case you want to update your GridView on Button Click, you need to provide the following line of code inside your triggers:

<asp:AsyncPostBackTrigger ControlID="btnUpdate" EventName="Click" />

Here is your Updated GridView:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
  <ContentTemplate>
    <asp:GridView
      ID="GridView1"
      runat="server"
      AutoGenerateSelectButton="True"
      BackColor="White"
      BorderColor="#CCCCCC"
      BorderStyle="None"
      BorderWidth="1px"
      CellPadding="3"
      ColumnName="test"
      CssClass="auto-style14"
      EnableViewState="false"
      Font-Size="Medium"
      HorizontalAlign="Left"
      AutoPostBack="true"
      OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
      Width="1010px"
    >
      <Columns>
        <asp:ButtonField Text="Details" />
      </Columns>
      <FooterStyle BackColor="White" ForeColor="#000066" />
      <HeaderStyle
        BackColor="#006699"
        BorderStyle="Solid"
        Font-Bold="True"
        ForeColor="White"
        HorizontalAlign="Center"
        VerticalAlign="Middle"
      />
      <PagerStyle
        BackColor="White"
        ForeColor="#000066"
        HorizontalAlign="Left"
      />
      <RowStyle ForeColor="#000066" />
      <SelectedRowStyle
        BackColor="#669999"
        Font-Bold="True"
        ForeColor="White"
      />
      <SortedAscendingCellStyle BackColor="#F1F1F1" />
      <SortedAscendingHeaderStyle BackColor="#007DBB" />
      <SortedDescendingCellStyle BackColor="#CAC9C9" />
      <SortedDescendingHeaderStyle BackColor="#00547E" />
      <RowStyle HorizontalAlign="Center" />
    </asp:GridView>
  </ContentTemplate>
  <Triggers>
    <asp:AsyncPostBackTrigger
      ControlID="GridView1"
      EventName="SelectedIndexChanged" />
  </Triggers>
</asp:UpdatePanel>