I have a user control in which there is a gridview and a button that is used to insert data, I want to update the grid view after the submission of the data without reloading the whole page. This is my user control's gridview code. <div id="ComplianceCommentDiv" style="border-width: 0px; border-spacing: 2px; border-style: solid; border-color: #abab9d; overflow: auto; vertical-align: top;">
<asp:GridView ID="GridViewComplianceComment" runat="server" DataKeyNames="ID" AutoGenerateColumns="false" AllowPaging="false" Width="100%" CssClass="Gridtbl" CellPadding="2"
OnRowDataBound="GridViewComplianceComment_RowDataBound" OnRowEditing="btnAdditionalNotes_Click">
<Columns>
<asp:TemplateField Visible="false">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label runat="server" ID="lblID" Text='<%#Eval("LogID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="ID" DataField="ID" Visible="false">
<ItemStyle VerticalAlign="Middle" HorizontalAlign="Left" />
<HeaderStyle VerticalAlign="Middle" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField HeaderText="Log ID" DataField="LogID">
<ItemStyle VerticalAlign="Middle" HorizontalAlign="Left" Width="100px" />
<HeaderStyle VerticalAlign="Middle" HorizontalAlign="Left" Width="100px" />
</asp:BoundField>
<asp:BoundField HeaderText="Comments" DataField="StatusComment">
<ItemStyle VerticalAlign="Middle" HorizontalAlign="Left" Wrap="true" />
<HeaderStyle VerticalAlign="Middle" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField HeaderText="Action" DataField="Action" Visible="true">
<ItemStyle VerticalAlign="Middle" HorizontalAlign="Left" Wrap="true" />
<HeaderStyle VerticalAlign="Middle" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField HeaderText="Date Added" DataField="CreatedDate">
<ItemStyle VerticalAlign="Middle" HorizontalAlign="Left" Width="100px" />
<HeaderStyle VerticalAlign="Middle" HorizontalAlign="Left" Width="100px" />
</asp:BoundField>
<asp:BoundField HeaderText="Created By" DataField="CreatedBy">
<ItemStyle VerticalAlign="Middle" HorizontalAlign="Left" Width="100px" />
<HeaderStyle VerticalAlign="Middle" HorizontalAlign="Left" Width="100px" />
</asp:BoundField>
<%-- <asp:TemplateField HeaderText="" ItemStyle-Width="100">
<ItemTemplate>
<asp:Button ID="btnAdditionalNotes" runat="server" Text="Additional Notes" Visible= false OnClick="btnAdditionalNotes_Click"/>
</ItemTemplate>
</asp:TemplateField>--%>
</Columns>
</asp:GridView>
<asp:Button ID="btnAdditionalNotes" runat="server" Text="Additional Notes" Visible="false" Style="float: right; border-left: 2px solid white; border-radius: 5px;" CssClass="bt-or" OnClick="btnAdditionalNotes_Click" />
<asp:Panel runat="server" ID="Message" Visible="False">
<div style="padding: 10px;">
<asp:Label runat="server" ID="MessageText1" Text="No records found."></asp:Label>
</div>
</asp:Panel>
</div>
this is my AJAX to save data and the C# code
function ShowAdditionalcommentsdiv(Logid, Status, AdditionalNoteComments) {
//debugger;
$.ajax({
type: "POST",
url: "/Search/DDetail.aspx/SaveAdditionalNote",
data: JSON.stringify({
logId: Logid,
status: Status,
additionalNoteComments: AdditionalNoteComments,
comment: ""
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
//debugger;
if (data.d != 0) {
alert("Additional comment added");
/*window.location.reload();*/
//ReloadGridView()
}
}
});
}
public static int SaveAdditionalNote(int logId, string status, string additionalNoteComments, string comment) { int response = 98169; try { DriverBasicInfoController _driverbasicinfocontroller = new DriverBasicInfoController(new DriverBasicInfoRepositary()); _driverbasicinfocontroller.UpdateComplianceStatusComment(logId, status, additionalNoteComments, comment); //return JsonConvert.SerializeObject(additionalNoteComments); response = logId; //ComplianceAdditionalCommentList(logId); } catch (Exception ex) { SafetyLogger.Logger.WriteErrorLog(SafetyPortal.Loggers.LogEntity.LogTypes.Exception, "Some Error Occured in getOwnerDetails", ex); response = 0; } return response; }