Hi, I followed the article Nested GridView Example in ASP.Net using C# and VB.Net by Mudassar. It is a great article and very simple to follow. I easily modified it to suit my needs and added several more levels to the nested GridView.
I am a VB.net Programmer and I have never used ASP.net or JQuery before. However I have a question I hope you can help with.
The data I am using is very large and with the "OnRowDataBound" events, the Page is Pre loading all the data into the gridviews and the Plus/Minus images are just displaying/hiding the nested gridviews. The question is "How to make the nested gridviews populate dynamically?" I want to have the nested gridviews to databind when the plus image is clicked.
What I have tried.
I added the below code to the Plus image click Function to execute the server-side "BindData" Function. however I don't know enough about ASP or Jquery to get the GridViewRowData to send to the server-side function.
$("[src*=plus]").live("click", function () {
$.ajax({
type: "POST",
url: "Main.aspx/BindData",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function(err) {
alert("err");},
success: function (msg) {
// Do something interesting here.
alert("ok")
}
});
$(this).closest("tr").after("<tr><td></td><td colspan = '999' width = '100%'>" + $(this).next().html() + "</td></tr>")
$(this).attr("src", "images/minus.png");
});
Server Side "BindData"
<System.Web.Services.WebMethod()> _
Public Shared Sub BindData(ByVal str As String)
Dim gvOrders As GridView = TryCast(e.Row.FindControl("gvCustomers"), GridView)
gvOrders.DataSource = GetData(String.Format("select cusNo,cusName from Customers where cusRepNo = '" & e.Row.DataItem("repno").ToString & "'"))
gvOrders.DataBind()
End Sub
Thank you for any help.