I am using customized user control wrapper. this has one dropdownbox with values populated from database.
here is the code of .ascx.cs file ....
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data;
namespace umbracotest { public partial class BookList : System.Web.UI.UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack || DropDownList1.SelectedValue.Length.ToString() == "0") { fillBooks(DropDownList1);
} }
private void fillBooks(DropDownList DropDownList1) { book b = new book(); string st = "select book_id, book_name from book_master";
DataSet ds = b.fetchdata(st, null); // dynamically fill book type in dropdownlist DataTable dt = ds.Tables[0];
if (!string.IsNullOrEmpty(_umbval)) { DropDownList1.SelectedValue = _umbval; }
} }
#region IUsercontrolDataEditor Members
private string _umbval;
public object value { get { return DropDownList1.SelectedValue; //throw new NotImplementedException(); } set { _umbval = value.ToString(); //throw new NotImplementedException(); } }
#endregion } }
now on before publish event I am inserting this dropdown box value to another DB. this work fine....
now I want to replace dropdownbox with checkbox list, so that user can select multiple values and so I can insert multiple records in DB on before publish event.... so how to get and set values for this in above code....
currently my before publish event code is as follows
namespace umbracotest { public class AppBase : umbraco.BusinessLogic.ApplicationBase { public AppBase() { Document.BeforePublish += new Document.PublishEventHandler(Document_BeforePublish); }
Don't know why you're writing the values for the datatype to your own tables (you must have a reason for that), but if you really want to save the values into your own custom tables on before publish, then you'd need to do almost the same as your code above, only difference is that the value returned from
will most probably be a comma separated list of values. So, split up that value using .Split(), iterate the values and perform a b.insertBookNode() for each value.
I have naother question now. I am updating the listbox values in DB on before publish. But it then gives error of unique key constraints. so want to know that when before publish event actually fires... as on save and then publish also give DB UK constraint error and directly publish button also give this error.
on before publish or after publish... I get the same error................ when i update DB through for loop in which I am passing selected values of checkboxlist
Server Error in '/' Application.
Violation of UNIQUE KEY constraint 'IX_BOOK_NODE_MAPPING'. Cannot insert duplicate key in object 'dbo.BOOK_NODE_MAPPING'. The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Violation of UNIQUE KEY constraint 'IX_BOOK_NODE_MAPPING'. Cannot insert duplicate key in object 'dbo.BOOK_NODE_MAPPING'. The statement has been terminated.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
get and set values from checkbox list
I am using customized user control wrapper. this has one dropdownbox with values populated from database.
here is the code of .ascx.cs file ....
now on before publish event I am inserting this dropdown box value to another DB. this work fine....
now I want to replace dropdownbox with checkbox list, so that user can select multiple values and so I can insert multiple records in DB on before publish event.... so how to get and set values for this in above code....
currently my before publish event code is as follows
can anybody help.. I am using umbraco 4.7 and new to this.
Don't know why you're writing the values for the datatype to your own tables (you must have a reason for that), but if you really want to save the values into your own custom tables on before publish, then you'd need to do almost the same as your code above, only difference is that the value returned from
will most probably be a comma separated list of values. So, split up that value using .Split(), iterate the values and perform a b.insertBookNode() for each value.
Hope this helps.
Regards,
/Dirk
I have naother question now. I am updating the listbox values in DB on before publish. But it then gives error of unique key constraints. so want to know that when before publish event actually fires... as on save and then publish also give DB UK constraint error and directly publish button also give this error.
on before publish or after publish... I get the same error................ when i update DB through for loop in which I am passing selected values of checkboxlist
Server Error in '/' Application.
Violation of UNIQUE KEY constraint 'IX_BOOK_NODE_MAPPING'. Cannot insert duplicate key in object 'dbo.BOOK_NODE_MAPPING'.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Violation of UNIQUE KEY constraint 'IX_BOOK_NODE_MAPPING'. Cannot insert duplicate key in object 'dbo.BOOK_NODE_MAPPING'.
The statement has been terminated.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
is working on a reply...