Having trouble displaying data from a SQL database in a GridView on a webpage using AJAX post method? You're not alone. Many face the same issue of the grid appearing empty despite fetching data from the database.
If you want to populate your GridView with data upon button click, consider revisiting your code and make sure you are correctly binding the data fetched through AJAX post method.
// C# code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDummyRow();
}
}
private void BindDummyRow()
{
// Create dummy DataTable for GridView
}
[WebMethod]
public static string GetCarService()
{
// Fetch Car Service data from the database
}
// JavaScript code
function GridDisplay(){
GetCarService();
}
// More JavaScript code...
// ASPX markup
<asp:Button runat="server" ID="modalTransportSearchButton" Text="Search" OnClientClick="GridDisplay();" Width="100px" />
// The rest of the GridView markup here...