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
2
  • Looks fine at the first glance. What line throws the error? Commented May 4, 2017 at 9: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 Commented May 4, 2017 at 9:37

2 Answers 2

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"), ...)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Andrei. All i had to do was to use "&" instead of "+"
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.

Comments

Your Answer

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