开发者

Fill gridview using javascript on selected tree node value

my requirement is to get the result in gridview based on the treeview node selection using javascript i.e. client scripting. Currently the same can be achieved using server 开发者_运维百科side scripting, but i want to do this without postback and without using selectednodeindexchanged event. Pls. help me to solve this problem.


The solution is quite involved but goes something like this:

  • Use the Page.GetCallbackEventReference method to make an XmlHttpRequest back to the server and retrieve a json object that will be used to populated the grid.
  • See the System.Web.Script.Serialization namespace for pointers on how to convert your objects to JSON.
  • Create a JavaScript closure to encapsulate your grid update logic. Something like:
var vm = {
  someField: 'test',

  init: function() {

  },

  update: function(data) {
     var grid = document.getElementById('yourGrid');
     // loop through the data and set the innerHTML on the cells to whatever your data is.
  }
}

setTimeout(function() {
  vm.init();
}, 100);

// In the aspx/ascx
//when the callback completes convert the json to an object like this
var d = eval('(' + data + ')');
//call update on your object
vm.update(data)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜