0

I have looked for other solutions here on StackOverflow but i cant seem to figure it out. I have this linkbutton in a datagrid:

    <asp:LinkButton 
        ID="lnkname" runat="server"
        Text='<%#Eval("Titel") %>'
        PostBackUrl='<%#"Details.aspx?ID="+Eval("ID").toString()%>'
        CausesValidation="false">
    </asp:LinkButton>

and this is the paramater:

<asp:ControlParameter ControlID="txtTitel" DefaultValue="*" Name="Titel" 
PropertyName="Text" Type="String" ConvertEmptyStringToNull="False" />

I want to take the ID value to the next page : details.aspx but i get the following error:

Input string was not in a correct format. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

I know it has something to do with ID being a INT but I cant figure out how to fix it.

NOTE: I do it in VB.NET

2 Answers 2

2

There is problem in casting it to string

+Eval("ID").toString()

use this

PostBackUrl='<%# "Details.aspx?ID="+Eval("ID").ToString() %>'

The .toString() should be ToString()

Edit 1

Or you can use

Try using a HyperLinkField

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield.aspx

<asp:HyperLinkField
                 HeaderText="Client IP"
                 DataNavigateUrlFields="IP"
                 DataNavigateUrlFormatString="Details.aspx?id={0}"
                 DataTextField="ID"
                 DataTextFormatString="{0}"/>
Sign up to request clarification or add additional context in comments.

3 Comments

Shamefully I cant give you a rep+ as I am a starter @ stack overflow... But I thank you very much! Its working fine now. Thank you for your time, Kind regards
kindly put your new html of asp link button
You are welcome and there is nothing wrong for being starter :)
0

If you need to pass multiple parameters then you can use & between them For example

PostBackUrl='<%# "Details.aspx?ID="+Eval("ID")+"&x=50" %>'

Important

Whenever you are concatenating(joining) a variable of any type like Eval("ID") value to a string like "Details.aspx?ID=", You do not need to write ToString() for casting becasue concatenation does this casting implicitly (automatically). I am sure about this behaviour for C# and VB.NET

So you could write simply

PostBackUrl='<%# "Details.aspx?ID="+Eval("ID") %>'

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.