-1

I'm using BOT Framework v 3 i have an adaptive card that takes input from the user and i want the values in Dropdown to be dynamic is it possible.here is the adaptive card design code as you can see I have entered the choices manually instead it want it to be dynamic from the database

var card = new AdaptiveCard()
{
    Body = new List<CardElement>()
    {
        new TextBlock()
        {
            Color = TextColor.Attention,
            Weight = TextWeight.Bolder,
            Size = TextSize.Medium,
            Text = "Select a title",
        },
        new ChoiceSet()
        {
            Id = "title",
            Style = ChoiceInputStyle.Compact,
            IsRequired = false,
            IsMultiSelect = false,
            Value = "1",
            Choices = new List<Choice>()
            {
                new Choice()
                {
                    Title = "Swiss cargo",
                    Value = "Swiss cargo",
                },
                new Choice()
                {
                    Title = "ticket booking",
                    Value = "ticket booking",
                },
            },
        },
    },
};
6
  • Welcome to Stack Overflow! Can you please provide a Minimal, Complete, and Verifiable example of what you've tried so far? Commented Mar 21, 2019 at 6:26
  • Hello and welcome to Stack Overflow, you are expected to show your attempt first and show where you are encountering a problem, please go through How to ask and How to create a minimum complete verifiable example Commented Mar 21, 2019 at 6:44
  • Are you using the Microsoft.AdaptiveCards NuGet package? You should really be using the one just called AdaptiveCards instead. Commented Mar 22, 2019 at 0:30
  • This looks like it's more of a question about using data from your database than a question about Adaptive Cards. Can you show us how you're retrieving the data? Commented Mar 22, 2019 at 0:33
  • Is my answer acceptable? Commented Mar 25, 2019 at 22:31

1 Answer 1

0

Assuming you can get your data into a list of strings, your Adaptive Card can easily be constructed dynamically using Linq. If you want to keep using the same Adaptive Cards library, it would look like this:

var data = new List<string> { "Swiss cargo", "ticket booking" };

var card = new AdaptiveCard()
{
    Body = new List<CardElement>()
    {
        new TextBlock()
        {
            Color = TextColor.Attention,
            Weight = TextWeight.Bolder,
            Size = TextSize.Medium,
            Text = "Select a title",
        },
        new ChoiceSet()
        {
            Id = "title",
            Style = ChoiceInputStyle.Compact,
            IsRequired = false,
            IsMultiSelect = false,
            Value = "1",
            Choices = data.Select(item => new Choice { Title = item, Value = item }).ToList(),
        },
    },
};
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.