0

I'm trying to pass multiple values through command argument tag in a listview. All the questions here are referring to GridView instead of a listview (I'm not sure if it makes a difference). I'm getting an error that Input String is not in correct format.

My code is:

aspx:

<asp:Button runat="server" Text="View Details" CssClass="button" CommandName="ViewApplicationDetails" CommandArgument='<%# Eval("id") + "|" + Eval("email") + "|" + Eval("application_hash")%>'/>

VB.NET:

Private Sub ListView1_ItemCommand(sender As Object, e As ListViewCommandEventArgs) Handles ListView1.ItemCommand
    If e.CommandName = "ViewApplicationDetails" Then
        Dim strAttributes As String()

        strAttributes = e.CommandArgument.ToString().Split("|")
        'Do something 
    End If
End Sub
  • Looks fine at the first glance. What line throws the error? – Andrei May 04 '17 at 09:34
  • the line that has asp button in it. The error is "System.FormatException: Input string was not in a correct format." It works fine when i keep one value in the command argument –  May 04 '17 at 09:37

2 Answers2

1

String concatenation with "+" might be unreliable at times in VB.Net. See this thread for discussion. That could be what you are facing. Things to try instead are "&" operator:

Eval("id") & "|" & Eval("email") & ...

or String.Format (readability boost for free):

String.Format("{0}|{1}|{2}", Eval("id"), Eval("email"), ...)
Community
  • 1
  • 1
Andrei
  • 55,890
  • 9
  • 87
  • 108
1

Can you please try with this

String.Format method:

CommandArgument='<%# String.Format("{0} {1} {2}", DataBinder.Eval(Container, "DataItem.id"), DataBinder.Eval(Container, "DataItem.email"), DataBinder.Eval(Container, "DataItem.application_hash")) %>'

Please let me know whether you are able to fix.

Techygal
  • 11
  • 3