code_junkie

getting selected check box value in Mvc asp.net

Nov 13th, 2011
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. <div id="pnlSent" style="display: none">
  2. <%= Html.DropDownList("select","msgtype") %>
  3. <% foreach (Usp_GetUserMessagesResult w in (List<Usp_GetUserMessagesResult>)ViewData["UListM"])
  4. { %>
  5. <li>
  6. <div class="question-info">
  7.  
  8. <input id="Checkbox1" type="checkbox" onclick="function() { alert("df") ; } " />
  9.  
  10. <div class="views count"><span></span></div>
  11. <div class="question">
  12. <div class="meta">Subject: <%= w.Subject %></div>
  13. <div class="meta">To: <%= w.Username %></div>
  14. <h3 class="title"><%= Html.Encode(w.Mesg)%></h3>
  15. </div>
  16. </div>
  17. </li>
  18. <% } %>
  19.  
  20. </div>
  21.  
  22. <% using(Html.BeginForm("Retrieve", "Home")) %>//Retrieve is the name of the action while Home is the name of the controller
  23. <% { %>
  24. <%foreach (var app in newApps) { %>
  25. <tr>
  26. <td><%=Html.CheckBox(""+app.ApplicationId )%></td>
  27.  
  28. </tr>
  29. <%} %>
  30. <input type"submit"/>
  31. <% } %>
  32.  
  33. public ActionResult Retrieve()
  34. {
  35. //since all variables are dynamically bound you must load your DB into strings in a for loop as so:
  36. List<app>=newApps;
  37. for(int i=0; i<app.Count;i++)
  38. {
  39.  
  40.  
  41. var checkbox=Request.Form[""+app[i].ApplicationId];
  42. // the reason you check for false because the Html checkbox helper does some kind of freaky thing for value true: it makes the string read "true, false"
  43. if(checkbox!="false")
  44. {
  45. //etc...almost same for other parameters you want that are in thr form
  46. }
  47.  
  48. }
  49. //of course return your view
  50. return View("Index");//this vaires by the name of your view ex: if Index.aspx
  51. }
  52.  
  53. <script type="text/javascript">
  54. function handleCheckbox( theBox ) {
  55. if( theBox.checked) {
  56. // do checked stuff
  57. }
  58. else {
  59. // do un-checked stuff
  60. }
  61. }
  62. </script>
  63.  
  64. ...
  65.  
  66. <input type="checkbox" value="<%= w.MessageID %>" onclick="handleCheckbox(this)" />
  67.  
  68. For Each ctrl As Control In Page.Controls
  69. If TypeOf ctrl Is TextBox Then
  70. CType(ctrl, TextBox).BackColor = clr
  71. Else
  72. If ctrl.Controls.Count > 0 Then
  73. SetTextBoxBackColor(ctrl, clr)
  74. End If
  75. End If
  76. Next
Add Comment
Please, Sign In to add comment