473,465 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Checkboxes in FormView bound to ObjectDataSource

Pao
I have a formview bounded to an objectdatasource.
All ok but I have some trouble with a checkbox: when I am in update
mode and I update the record, this field is never updated (no errors
thrown).
The field bounded in the database (MySql) is a string field
(ENUM('True','False') default 'False'.

The checkbox is correctly bounded in the itemtemplate and in the
edititemtemplate.

Here is the formview:
Expand|Select|Wrap|Line Numbers
  1. <asp:FormView ID="fwAgente" runat="server"
  2. AllowPaging="True"
  3. DataKeyNames="ID"
  4. DataSourceID="AgenteDataSource">
  5. <ItemTemplate>
  6. <table>
  7. <tr><td align="right"><b>ID:</b></td>
  8. <td><%# Eval("ID") %></td></tr>
  9.  
  10. <tr><td align="left" style="height:
  11. 21px"><b>Nome:</b></td><td style="width: 5px; height: 21px"><%#
  12. Eval("Nome") %></td></tr>
  13. <tr><td align="left"><b>Cognome:</b></td>
  14. <td style="width: 5px"><%# Eval("Cognome") %></td></tr>
  15. <tr><td align="left"><b>Telefono:</b></td>
  16. <td style="width: 5px"><%# Eval("Telefono") %></td></tr>
  17. <tr>
  18. <td style="width:7%">Annullato: </td>
  19. <td style="width:6%">
  20. <asp:CheckBox ID="chkAnnAg"
  21. runat="server" Enabled="false"
  22. Checked ='<%#
  23. Convert.ToBoolean(Eval("annullato")) %>'  />
  24. </td>
  25. </tr>
  26. <tr>
  27. <td colspan="2">
  28. <asp:LinkButton ID="EditButton"
  29. Text="Edit"
  30. CommandName="Edit"
  31. RunAt="server"/>
  32. &nbsp;
  33. <asp:LinkButton ID="NewButton"
  34. Text="New"
  35. CommandName="New"
  36. RunAt="server"/>
  37. &nbsp;
  38. <asp:LinkButton ID="DeleteButton"
  39. Text="Delete"
  40. CommandName="Delete"
  41. RunAt="server"/>
  42. </td>
  43. </tr>
  44. </table>
  45. </ItemTemplate>
  46.  
  47. <EditItemTemplate>
  48. <table>
  49. <tr><td align="right"><b>ID:</b></td>
  50. <td><asp:TextBox ID="EditIDTextBox"
  51. Enabled="false"
  52. Text='<%# Bind("ID") %>'
  53.  
  54. RunAt="Server"
  55. /></td></tr>
  56.  
  57. <tr><td align="right"><b>Nome:</b></td>
  58. <td><asp:TextBox ID="EditNomeTextBox"
  59. Text='<%# Bind("Nome")
  60. %>'
  61. RunAt="Server"
  62. /></td></tr>
  63. <tr><td align="right"><b>Cognome:</b></td>
  64. <td><asp:TextBox ID="EditCognomeTextBox"
  65. Text='<%#
  66. Bind("Cognome") %>'
  67. RunAt="Server"
  68. /></td></tr>
  69. <tr><td align="right"><b>Telefono:</b></td>
  70. <td><asp:TextBox ID="EditTelefonoTextBox"
  71.  
  72. Text='<%#
  73. Bind("Telefono") %>'
  74. RunAt="Server"
  75. /></td></tr>
  76.  
  77. <tr><td align="right"><b>Annullato:</b></td>
  78. <td style="width:6%">
  79. <asp:CheckBox ID="chkAnnAg"
  80. runat="server" Enabled="true"
  81. Checked ='<%#
  82. Convert.ToBoolean(Eval("annullato")) %>'  />
  83. </td>
  84. </tr>
  85.  
  86. <tr>
  87. <td colspan="2">
  88. <asp:LinkButton ID="UpdateButton"
  89. Text="Update"
  90. CommandName="Update"
  91. RunAt="server"/>
  92. &nbsp;
  93. <asp:LinkButton ID="CancelUpdateButton"
  94. Text="Cancel"
  95. CommandName="Cancel"
  96. RunAt="server"/>
  97. </td>
  98. </tr>
  99. </table>
  100. </EditItemTemplate>
  101. <InsertItemTemplate>
  102. <table>
  103. <tr><td align="right"><b>Login:</b></td>
  104. <td><asp:TextBox ID="InsertLoginTextBox"
  105. Text='<%# Bind("Login")
  106. %>'
  107. RunAt="Server"
  108. /></td></tr>
  109.  
  110. <tr><td align="right"><b>Nome:</b></td>
  111. <td><asp:TextBox ID="InsertNomeTextBox"
  112. Text='<%# Bind("Nome")
  113. %>'
  114. RunAt="Server"
  115. /></td></tr>
  116.  
  117. <tr><td align="right"><b>Cognome:</b></td>
  118. <td><asp:TextBox
  119. ID="InsertCognomeTextBox"
  120. Text='<%#
  121. Bind("Cognome") %>'
  122. RunAt="Server"
  123. /></td></tr>
  124.  
  125. <tr><td align="right"><b>Telefono:</b></td>
  126. <td><asp:TextBox
  127. ID="InsertTelefonoTextBox"
  128. Text='<%#
  129. Bind("Telefono") %>'
  130. RunAt="Server"
  131. /></td></tr>
  132. <tr>
  133. <td colspan="2">
  134. <asp:LinkButton ID="InsertButton"
  135. Text="Insert"
  136. CommandName="Insert"
  137. RunAt="server"/>
  138. &nbsp;
  139. <asp:LinkButton ID="CancelInsertButton"
  140. Text="Cancel"
  141. CommandName="Cancel"
  142. RunAt="server"/>
  143. </td>
  144. </tr>
  145. </table>
  146. </InsertItemTemplate>
  147. </asp:FormView>
  148.  
and here is the objectdatasource:

Expand|Select|Wrap|Line Numbers
  1. <asp:ObjectDataSource ID="AgenteDataSource"
  2. runat="server"
  3. DataObjectTypeName="Reminder.Agente"
  4. TypeName="Reminder.Agente"
  5. DeleteMethod="Delete"
  6. InsertMethod="Insert"
  7. SelectMethod="GetDataTable"
  8. UpdateMethod="Update"
  9. OldValuesParameterFormatString="original_{0}"
  10. OnUpdated="AgenteDataSource_Updated"
  11. OnObjectCreated = "genteDataSource_ObjectCreated"
  12.  
  13. OnInserted="AgenteDataSource_Updated"
  14. OnDeleted="AgenteDataSource_Updated"
  15.         
  16.                 >
  17.  
  18. <SelectParameters>
  19. <asp:Parameter Name="vId" Type="String" />
  20. <asp:Parameter Name="vAnn" Type="String" />
  21. </SelectParameters>
  22. </asp:ObjectDataSource>
  23.  
and here is the declaration of the object

Expand|Select|Wrap|Line Numbers
  1. public class Agente
  2. {
  3. private MySqlConnection cnn = new MySqlConnection();
  4. protected int _id;
  5. protected string _login;
  6. protected string _nome;
  7. protected string _cognome;
  8. protected string _telefono;
  9. protected string _annullato;
  10. protected string _loginmod;
  11.  
  12. //public Agente(string login, string nome, string cognome, string
  13. telefono)
  14. public Agente()
  15. {}
  16.  
  17. public int ID
  18. {
  19. get { return _id; }
  20. set { _id = value; }
  21. }
  22. public string Login
  23. {
  24. get { return _login; }
  25. set { _login = value; }
  26. }
  27. public string Nome
  28. {
  29. get {return _nome;}
  30. set { _nome = value; }
  31. }
  32. public string Cognome
  33. {
  34. get { return _cognome; }
  35. set { _cognome = value; }
  36. }
  37. public string Telefono
  38. {
  39. get { return _telefono; }
  40. set { _telefono = value; }
  41. }
  42. public string Annullato
  43. {
  44. get { return _annullato; }
  45. set { _annullato = value.ToString(); }
  46. }
  47.  
here is the update method of Agente Object:

Expand|Select|Wrap|Line Numbers
  1. public void Update(Agente _A)
  2. {
  3. Agente AgNow = new Agente(); //AgNow=dati presenti adesso da
  4. aggiornare
  5. AgNow.AutoLoadByID(_A.ID);
  6.  
  7. //aggiorno i dati di AgNow con quelli dell'update se presenti
  8. //if (_A.ID != null) AgNow.ID = _A.ID;
  9. if (_A.Login != null) AgNow.Login = _A.Login;
  10. if (_A.Nome != null) AgNow.Nome = _A.Nome;
  11. if (_A.Cognome != null) AgNow.Cognome = _A.Cognome;
  12. if (_A.Telefono != null) AgNow.Telefono = _A.Telefono;
  13. if (_A._annullato != null) AgNow.Annullato = _A.Annullato;
  14.  
  15. MySqlCommand cmd = new MySqlCommand();
  16. if (cnn.ConnectionString == string.Empty)
  17. cnn.ConnectionString =
  18. ConfigurationManager.ConnectionStrings["reminder_local"].ToString();
  19. cmd.Connection = cnn;
  20. cmd.CommandType = CommandType.StoredProcedure;
  21. cmd.Parameters.Add(new MySqlParameter("P_ID", AgNow.ID));
  22. cmd.Parameters.Add(new MySqlParameter("P_login", AgNow.Login));
  23. cmd.Parameters.Add(new MySqlParameter("P_nome", AgNow.Nome));
  24. cmd.Parameters.Add(new MySqlParameter("P_cognome",
  25. AgNow.Cognome));
  26. cmd.Parameters.Add(new MySqlParameter("P_telefono",
  27. AgNow.Telefono));
  28. cmd.Parameters.Add(new MySqlParameter("P_annullato",
  29. AgNow.Annullato));
  30. cmd.Parameters.Add(new MySqlParameter("P_loginmod",
  31. Glob.vLogin));
  32. cmd.CommandText = "spUpdateAgente";
  33.  
  34. try
  35. {
  36. if (cnn.State == ConnectionState.Closed)
  37. cnn.Open();
  38. cmd.ExecuteNonQuery();
  39. cnn.Close();
  40. }
  41. catch (MySqlException Exception)
  42. { throw (Exception); }
  43. }
  44.  
Jan 4 '07 #1
1 6547
Pao
I fiund the solution
it was a problem of conversion from bool (from checkbox.checked) to
string (my object property)
protected void AgenteDataSource_OnUpdating(object sender,
ObjectDataSourceMethodEventArgs e)
{
Agente _a = (Agente)e.InputParameters[0];
CheckBox _c = (CheckBox)fwAgente.FindControl("chkAnnAg");

if (_c.Checked)
_a.Annullato = "True";
else
_a.Annullato = "False";
}
so I change the property before the raise of the update method of my
business object.

Hope this helps

Jan 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: akylitis | last post by:
Question regarding the use of a FormView control. All I need is the ability to submit a form (insert a record) and return back a "Thank You". I am defaulting the FormView to "Insert" mode...
2
by: Dabbler | last post by:
In my Registrant FormView I have a DropDownList which loads data from a secondary SqlDataSource "sdsOfficeParks". I need the user to select an office park but save the selected value in the...
1
by: Uriah Piddle | last post by:
Hi, I have a FormView where nothing gets rendered past the opening <ItemTemplatetag. The FormView Header renders but nothing else. If I put garbage in an Eval statement, no errors are raised and...
0
by: kidders | last post by:
I have an business object bound to a formview with through an object datasource, in edit mode when i click update i receive the following error: The 'ActionID' property on the type specified by...
0
by: =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= | last post by:
Hello, I read some msdn and other articles about how does databinding among DataSource controls and FormView / GridView controls works but I still don't fully understand to this blackbox. I have...
8
by: =?Utf-8?B?QXNo?= | last post by:
Hi, I have an object, for example User. User contains various properties which i have been able to bind to successfully using wizards and the form view. However if the class User has a property...
2
by: J055 | last post by:
Hi I have 2 user controls and 1 parent page. One user control contains a Gridview and the other a FormView. When the GridView row Select command is fired it bubbles an event to the parent page...
6
by: Chris | last post by:
I want do my insert to a database using a formview bound to an objectdatasource. I also want to upload a file. I'm quite new to and this is just test code but Is there any way I can pass the file...
5
by: =?Utf-8?B?QWRhciBXZXNsZXk=?= | last post by:
Hi All, I have a GridView inside the EditItemTemplate of a FormView. Both FormView and GridView are data bound using an ObjectDataSource. When the FormView's ObjectDataSource object has a...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.