0

When I pass multiple arguments via

<asp:Button runat="server" ID="btnUpdate" Text="Update" 
            CssClass="btn btn-sm btn-success" 
            CommandName="UpdateCoordinator" 
            CommandArgument='<%# Bind("iUserID") & "," & Bind("siteID")%>' 
            CausesValidation="false" />

And in code behind I attempt to split the CommandArgument like this:

Dim commandArgs As String() = e.CommandArgument.ToString().Split(New Char() {","})
Dim iUserID As Integer = Val(commandArgs(0))
Dim iSiteID As Integer = Val(commandArgs(1))

I am only getting the first argument and the error

System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'

Any assistance to point out what I am missing would be fantastic!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
GeoffreyB
  • 11
  • 2
  • Based on your title this question and related answers might be helpful: https://stackoverflow.com/questions/9822827/how-to-pass-multiple-values-through-command-argument-in-asp-net – JakeofSpades Mar 23 '20 at 04:53
  • how is your `new Char()` array taking string members. – Gagan Deep Mar 23 '20 at 06:29

1 Answers1

0

I solved this by using Container.DataItem() in the definition of the Button.

<asp:Button runat="server" ID="btnUpdate" Text="Update" CssClass="btn btn-sm btn-success" CommandName="UpdateCoordinator" CommandArgument='<%# Container.DataItem("iUserID").ToString() & "," & Container.DataItem("siteID").ToString() %>' CausesValidation="false" />
GeoffreyB
  • 11
  • 2