0

I got some code to create new buttons programmatically.

foreach (DataRow dtRow in dtTable.Rows)
{
    string question_id = Convert.ToString(dtRow["QUESTION_ID"]);
    string question_text = Convert.ToString(dtRow["QUESTION_TEXT"]);
    var btn_system = new Button
    {
        ID = "btn_question" + question_id,
        Text = question_text,
        CssClass = "quest_buttons"
    };
    btn_system.Command += ButtonClick_Parent;
    btn_system.CommandArgument = Convert.ToString(question_id);
}

Now I would like to add multiple CommandArgument in line 12 of my code snippet. How can I do this from code behind?

Thanks in advance!

1
  • Maybe the easiest solution is passing all the arguments you want semicolon separated, and in your command use Split to get them Commented Oct 14, 2016 at 7:38

1 Answer 1

1

You need to pass multiple arguments as a string separating by some character and in event handler, you need to parse them. I have shown here using comma

btn_system.CommandArgument = "argument1,argument2,argument2,...";

then get this using below code

protected void ButtonClick_Parent(object sender, EventArgs e)
{
    Button button = (Button)sender;
    string[] commandArgs = button.CommandArgument.ToString().Split(',');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.