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!

Mostafiz
  • 7,243
  • 3
  • 28
  • 42
mabu
  • 286
  • 8
  • 26
  • Maybe the easiest solution is passing all the arguments you want semicolon separated, and in your command use `Split` to get them – Pikoh Oct 14 '16 at 07:38

1 Answers1

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(',');
}
Mostafiz
  • 7,243
  • 3
  • 28
  • 42