x First time here? Check out the FAQ
  • Avatar245posts267karma

    get and set values from checkbox list

    hetaurhet started this topic June 27, 2011 @ 07:17

    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,
            protected void Page_Load(object sender, EventArgs e)
                if (!Page.IsPostBack || DropDownList1.SelectedValue.Length.ToString() == "0")


            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 (dt != null)
                    DropDownList1.DataValueField = "BOOK_ID";
                    DropDownList1.DataTextField = "BOOK_NAME";
                    DropDownList1.DataSource = dt;

                    if (!string.IsNullOrEmpty(_umbval))
                        DropDownList1.SelectedValue = _umbval;


            #region IUsercontrolDataEditor Members

            private string _umbval;

            public object value
                    return DropDownList1.SelectedValue;
                    //throw new NotImplementedException();
                    _umbval = value.ToString();
                    //throw new NotImplementedException();


    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);

            void Document_BeforePublish(Document sender, PublishEventArgs e)

                Log.Add(LogTypes.Debug, sender.Id, "the document " + sender.Text + " is about to be published");

                if (sender.ContentType.Alias == "BooksPage")
                    //BookList bl = new BookList();
                    book b = new book();

                    //sender.ExpireDate = DateTime.Now.AddDays(14);

                //cancel the publishing
                //e.Cancel = true;

    can anybody help.. I am using umbraco 4.7 and new to this.

  • Avatar4387posts5195karma
    adminComment with ID: 81180
    Dirk De Grave posted this reply June 27, 2011 @ 07:29

    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.




  • Avatar245posts267karma
    Comment with ID: 81523
    hetaurhet posted this reply June 29, 2011 @ 10:53

    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.

  • Avatar245posts267karma
    Comment with ID: 81600
    hetaurhet posted this reply June 29, 2011 @ 04:39

    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:

    [SqlException (0x80131904): Violation of UNIQUE KEY constraint 'IX_BOOK_NODE_MAPPING'. Cannot insert duplicate key in object 'dbo.BOOK_NODE_MAPPING'.
    The statement has been terminated.]
    System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2030802
    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009584
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
    System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
    System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) +228
    System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +326
    System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
    book.insertBookNode(String bookid) +259
    UmbracoEvents.AppBase.Document_AfterPublish(Document sender, PublishEventArgs e) +434
    umbraco.cms.businesslogic.web.PublishEventHandler.Invoke(Document sender, PublishEventArgs e) +0
    umbraco.cms.businesslogic.web.Document.FireAfterPublish(PublishEventArgs e) +27
    umbraco.cms.businesslogic.web.Document.PublishWithResult(User u) +1519
    umbraco.cms.presentation.editContent.Publish(Object sender, EventArgs e) +236
    System.EventHandler.Invoke(Object sender, EventArgs e) +0
    umbraco.controls.ContentControl.savePublish(Object Sender, ImageClickEventArgs e) +46
    System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +115
    System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +120
    System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

Please login or Sign up To post replies