+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18

Thread: Building Dynamic Conditional Statement

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Building Dynamic Conditional Statement

    Anyone got an idea on how I could build a dynamic user-defined conditional statement? So, I want users to be able to select what properties to include in a conditional.

    I want users to be able to build there own conditionals so, ideally it would be something like:-
    Code:
    obj object = new obj();
    object.id=1;
    object.title="title";
    object.firstname="firstname";
    object.lastname="lastname";
    
    if (object.(ddlFirstOption.SelectedValue)==txtFirstOptionToCheck.Text)
    {
        //use object.(ddlFirstOption.SelectedValue)
    }else if (object.(ddlSecondOption.SelectedValue)==txtSecondObjectToCheck.text)
    {
       //use object.(ddlSecondOption.SelectedValue)
    }
    
    So a user could, for example, have a conditional where they selected title in the first option dropdown and enter "title" in the first option to check textbox.

    So, I guess the question is, can you dynamically choose the property of an object or do you always have to "hard-code" them?

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    So let me see if I understand you correctly. You want to select the text "Title" from the dropdown, then be able to enter a value for title in the textbox, and then populate the "Title" property of your object?
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by jmurrayhead View Post
    So let me see if I understand you correctly. You want to select the text "Title" from the dropdown, then be able to enter a value for title in the textbox, and then populate the "Title" property of your object?
    Not quite. I don't want to populate the value. It's for marketing emails.

    There will be a list of contacts and some of them might have a title (or firstname or whatever property they want to use) and some might not. So I want the user to be able to build a conditional themselves using dropdowns so they can select, for example:-

    if contact doesn't have a title
    use this property
    else if contact doesn't have a firstname
    use this property
    else
    use this property

    Or:-
    if contact's title="Mr"
    use this property
    else if contact doesn't have a title
    use this property
    else
    use this property

    That will then replace some field code inside the template email with whatever value is in the property they want to use.

    Does that make sense? Rather than making it fixed, I want to include some flexibility over what they can do.

    The mailing software they use at the moment allows you to include conditional code inside the email template so, they have code that equates to this conditional:-

    if contact doesn't have a title
    use Dear Generic Job Title
    else
    use Dear contact.title contact.firstname
    end if

  4. #4
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Quote Originally Posted by richyrich View Post
    Does that make sense?
    No, not really.

    The way you explain your logic doesn't make much sense (to me), but what it sounds like you need is Reflection. See here: System.Reflection Namespace and here: Using Reflection to Bind Business Objects to ASP.NET Form Controls
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  5. #5
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by jmurrayhead View Post
    No, not really.
    Hmm...OK...I'll try a hardcoded example...Using the example above, you might have the following code when you're building the emails to send.

    Inside the template, you might have:-
    Code:
    Dear <<_Salutation_>>
    
    And then you use this template to build an email for each contact. You want <<_Salutation_>> to be replaced with a property from each contact, but only if they have a title. So you would hard code something like:-
    Code:
    if(string.IsNullOrEmpty(contact.title))
    {
        Replace("<<_Salutation_>>","Generic Title");
    }else{
        Replace("<<_Salutation_>>",contact.title + " " + contact.lastname);
    }
    
    It is this conditional I want the user to be able to build themself.

    Making any more sense now?

  6. #6
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Yes, that makes more sense now and I still stand behind my reply of using Reflection. If your user selects "title", then chooses a different property of the contact object to use instead, you can use Reflection to take a string value and get the value of your contact property whose name matches that string value. So, if "LastName" is selected, then that string value will be used to determine which property to take the value from.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  7. #7
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    OK. That does make some sense. Basically it's mapping a collection of controls to an object's properties.

    Will need to work through some examples to see if I can get it working how I want. I guess it would be along the lines of create a "template" contact by binding it to a collection of controls and then compare this to each real contact in your contact list?

    Will have a bit more of a think about it and see what I can come up with.

    Thanks J..

  8. #8
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Quote Originally Posted by richyrich View Post
    Basically it's mapping a collection of controls to an object's properties.
    Yeah, something along those lines

    Quote Originally Posted by richyrich View Post
    I guess it would be along the lines of create a "template" contact by binding it to a collection of controls and then compare this to each real contact in your contact list?
    Not sure what you mean by '"template" contact'. You have an email template from which you're using to email a list of contacts. I'm assuming you pull all the contacts, perhaps an IList<Contact>, for example. Then you iterate through this list to send the email. You already have the contact object, so no need for a template. But what you'll do is use Reflection to grab the value of the specified property that you want to use based on the user's selections.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  9. #9
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Going back to my previous example, how would you build this using Reflection?
    Code:
    if(string.IsNullOrEmpty(contact.title))
    {
        Replace("<<_Salutation_>>","Generic Title");
    }else{
        Replace("<<_Salutation_>>",contact.title + " " + contact.lastname);
    }
    
    So, title would be something that is selected by the user. The value to check, in this case, empty (string.IsNullOrEmpty) is selected by the user. The value or object property to use if this condition is true is entered or selected by the user and the value or object property to use if this condition is false is entered or selected by the user. And also what field code to replace is entered or selected by the user.

  10. #10
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    How many possible options to check are there? And just to verify, the drop down lists contain the property names (i.e. Title, First Name, Last Name, etc.) and the textboxes contain the text to use if the property doesn't have a value. Correct?
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. sql statement with an iif statement inside
    By arloguth in forum Microsoft Access
    Replies: 7
    Last Post: June 7th, 2009, 11:31 PM
  2. Conditional JOIN in Stored Procedure
    By richyrich in forum MySQL
    Replies: 5
    Last Post: April 6th, 2009, 04:55 PM
  3. Dynamic Stored Procedure without Building Strings
    By jmurrayhead in forum SQL Code Samples
    Replies: 11
    Last Post: March 17th, 2009, 01:12 PM
  4. Conditional data on report
    By tuxalot in forum Microsoft Access
    Replies: 16
    Last Post: March 3rd, 2009, 11:18 PM
  5. iif statement
    By Barkol in forum Microsoft Access
    Replies: 4
    Last Post: June 6th, 2008, 12:12 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO