Refresh ASP.Net GridView after record gets updated using C# and SqlDataSource

Last Reply 12 days ago By Andrea

Posted 12 days ago

I have a GridView like below and I want to refresh the data of the grid after I grid editing.

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
    DataSourceID="EditCourseDB">
    <Columns>
        <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" Visible="false"></asp:BoundField>
        <asp:BoundField DataField="Title" HeaderText="Title"></asp:BoundField>
        <asp:BoundField DataField="Floor" HeaderText="Floor"></asp:BoundField>
        <asp:BoundField DataField="Capacity" HeaderText="Capacity"></asp:BoundField>
        <asp:BoundField DataField="TypeId" HeaderText="TypeId"></asp:BoundField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Button ID="Button1" Text="Get Value" runat="server" OnClick="GridView_Button_Click" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

 

            <asp:SqlDataSource ID="sqlDtSrcEditCourse" runat="server" ConnectionString="<%$ ConnectionStrings:KDUIS-v1ConnectionString %>"
                OnUpdating="sqlDtSrcEditCourse_Updating" 
                SelectCommand="SELECT * FROM [EDU_Room]"
                UpdateCommand="Update [EDU_Room] SET [Title]=@Title,[Floor]=@Floor,[Capacity]=@Capacity WHERE [id]=@id">
                <SelectParameters>
                    <asp:ControlParameter ControlID="TxtId" Name="Id" PropertyName="Text" Type="Byte" />
                </SelectParameters>
                <UpdateParameters>

                   <asp:ControlParameter ControlID="TxtTitle" Name="Title" PropertyName="Text" Type="String" />
                   <asp:ControlParameter ControlID="TxtFloor" Name="Floor" PropertyName="Text" Type="Byte" />
                   <asp:ControlParameter ControlID="TxtCapacity" Name="Capacity" PropertyName="Text" Type="Byte" />
                   <asp:ControlParameter ControlID="TxtId" Name="Id" PropertyName="Text" Type="Byte" />

                </UpdateParameters>
            </asp:SqlDataSource>

 

Title: <asp:TextBox ID="TxtTitle" runat="server"></asp:TextBox><br />
Floor: <asp:TextBox ID="TxtFloor" runat="server"></asp:TextBox><br />
Capaciry: <asp:TextBox ID="TxtCapacity" runat="server"></asp:TextBox><br />
Id: <asp:TextBox ID="TxtId" runat="server"></asp:TextBox>

 

protected void Save(object sender, EventArgs e)
{
    sqlDtSrcEditCourse.Update();
}

Now How can I refresh the Data of my Grid view 

Immediately after Editing?
Posted 12 days ago
Hi @dorsa,
Please try the following

Refresh GridView after data gets updated using C# in ASP.Net

It might help you.

Cheers Andrea.