code_junkie

asp:CheckBoxField in GridView - VS 2008

Nov 13th, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. <Columns>
  2. <asp:CheckBoxField DataField="Locked" Visible="true" AccessibleHeaderText="On Hold" ReadOnly="false"/>
  3. </Columns>
  4.  
  5. protected void grdSomething_RowDataBound ( Object sender, GridViewRowEventArgs e )
  6. {
  7. if ( e.Row.RowType == DataControlRowType.DataRow )
  8. {
  9. BusinessObject data = ( BusinessObject ) e.Row.DataItem;
  10. CheckBox chkLocked = ( CheckBox ) e.Row.FindControl( "chkLocked" );
  11. chkLocked.Checked = data.Locked;
  12. }
  13. }
  14.  
  15. [WebMethod]
  16. public static void ToggleLockedStatus ( string key )
  17. {
  18. if ( BusinessObjectDictionary.ContainsKey( key ) )
  19. {
  20. BusinessObjectDictionary[ key ].Locked = !BusinessObjectDictionary[ key ].Locked;
  21. }
  22. else
  23. {
  24. throw new Exception( "The business object specified was not found." );
  25. }
  26. }
  27.  
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Text;
  31. using System.Linq;
  32. using System.Data.Linq;
  33. using System.Data.Linq.Mapping;
  34. using System.Web;
  35. using System.Web.UI.WebControls;
  36.  
  37.  
  38. namespace Web.Library.Controls.Commands
  39. {
  40. public class CommandCheckBox : System.Web.UI.WebControls.CheckBox
  41. {
  42. private static readonly object EventCommand = new object();
  43.  
  44. public event CommandEventHandler Command
  45. {
  46. add
  47. {
  48. Events.AddHandler(EventCommand, value);
  49. }
  50. remove
  51. {
  52. Events.RemoveHandler(EventCommand, value);
  53. }
  54. }
  55.  
  56. public string CommandName
  57. {
  58. get
  59. {
  60. if (this.ViewState["CommandName"] == null)
  61. return string.Empty;
  62.  
  63. return (string)this.ViewState["CommandName"];
  64. }
  65. set { this.ViewState["CommandName"] = value; }
  66. }
  67.  
  68. public string CommandArgument
  69. {
  70. get
  71. {
  72. if (this.ViewState["CommandArgument"] == null)
  73. return string.Empty;
  74.  
  75. return (string)this.ViewState["CommandArgument"];
  76. }
  77. set { this.ViewState["CommandArgument"] = value; }
  78. }
  79.  
  80. protected virtual void OnCommand(CommandEventArgs args)
  81. {
  82. CommandEventHandler commandEventHand = Events[EventCommand] as CommandEventHandler;
  83.  
  84. if (commandEventHand != null)
  85. {
  86. commandEventHand(this, args);
  87. }
  88.  
  89. base.RaiseBubbleEvent(this, args);
  90. }
  91.  
  92. protected override void OnCheckedChanged(EventArgs e)
  93. {
  94. base.OnCheckedChanged(e);
  95.  
  96. CommandEventArgs args = new CommandEventArgs(this.CommandName, this.CommandArgument);
  97.  
  98. this.OnCommand(args);
  99. }
  100.  
  101.  
  102. public CommandCheckBox()
  103. {
  104. }
  105.  
  106. }
  107. }
  108.  
  109. <asp:CheckBox ID="MyCheckBox" runat="server" Checked='<%#Eval("Locked")' ... />
Add Comment
Please, Sign In to add comment