Posts

Showing posts with the label javascript

Using jqGrid with JsonResult in ASP.NET MVC 3

I have been working on an ASP.NET MVC 3 project with a C# backend, and I wanted to get a grid going that had grouping capabilities. I came across jqGrid and decided to give it a try. I discovered a blog post which got me close, but it still took a bit of doing. It turned out to be a pain, but I managed to get basic data display working (I'll try to update this post when I get grouping working). I decided to post the code because it wasn't straightforward, and all of the other blog & forum posts on the topic didn't quite have a complete solution. The code has a bit more detail than is necessary for this post, but I hope it is useful. Here is my HTML... My javascript looks like this... There are a couple things to note. Line 3: The url attribute. It took a bit of trial & error to figure out this url format for my controller method. "Asset" is the controller (my actual controller name is "AssetController"), and "GetGridConten...

Making a standard ASP.NET listbox do multiselect without holding Ctrl

I've always hated that users of a standard ASP.NET listbox control must hold ctrl to select multiple items. It's just a recipe for bad/incomplete data input. So, I set out to see if I could make the listbox do multiselect without holding the ctrl key. I know that there are third party controls out there that accomplish this more elegantly, but I wanted to see if it was possible with a standard control. I managed to get it going with some javascript help. First, I defined my listbox & gave it an onclick event to fire a javascript method: Second, I created the javascript method (the last one below) to loop through the listbox elements, select all of the items previously selected, and toggle the one the user clicked. //This array holds the "selected" state of each listbox item var selectedClientPermissions = []; //Because I'm working with a databound listbox, I grab the selected values //on page load & put them in the array. function pageLoad() { ...