passing parameters to a metod using Eval()

Last post 08-08-2007 11:02 AM by bcanonica. 6 replies.

Sort Posts:

  • passing parameters to a metod using Eval()

    08-04-2007, 5:34 PM
    • Loading...
    • bcanonica
    • Joined on 12-08-2006, 9:11 PM
    • Philadelphia, PA
    • Posts 293

    What I am trying to do is pass a the parameter to a method using the Eval() inside of a hyperlink inside the itemtemplate of a repeater.  I keep getting errors no matter what I try.  This seems like it can be done fairly easy, but I am stuck on it.  What parameters does my method need?

     What am i doing wrong?  Still getting invalid arguements!

    <asp:Repeater ID="_repComments" runat="Server">

    <ItemTemplate>

    <asp:LinkButton ID="LinkButton1" runat="server" onClick='OnDeleteComment(Eval("ID"))' >Delete</asp:LinkButton>

    </ItemTemplate>

     

    </asp:Repeater>
     -----Code Behind---------

    public void OnDeleteComment(int commentid)

    {

    }

    Do I need an object parameter or something? 

    Remember to mark any post that is helpful as an answer and change posts status to Resolved to help others in the future.

    cheers,

    BC

    http://voidimpossible.com
  • Re: passing parameters to a metod using Eval()

    08-04-2007, 5:52 PM
    Answer
    • Loading...
    • XIII
    • Joined on 07-01-2002, 3:59 AM
    • Essen, Belgium
    • Posts 10,125
    • Moderator
      TrustedFriends-MVPs

    Hi,

    the signature of the OnClick eventhandler of a LinkButton control's (object sender, EventArgs e). The way you're trying to do it can't be done since that signature doesn't match.

    You should however be able to handle this in the ItemCommand eventhandler of the Repeater control itself like this: http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemcommand.aspx.

    Grz, Kris.

    Read my blog | Members are volunteers so please keep out the (it's urgent | asap | reply me directly) stuff. Nobody's interested in that.
  • Re: passing parameters to a metod using Eval()

    08-05-2007, 12:43 PM
    • Loading...
    • bcanonica
    • Joined on 12-08-2006, 9:11 PM
    • Philadelphia, PA
    • Posts 293

    Can you override the method to take the value from the Eval()?  That would be exactly what I am looking for, but that doesn't seem to work either.  Any other ideas?

     

    BC

    Remember to mark any post that is helpful as an answer and change posts status to Resolved to help others in the future.

    cheers,

    BC

    http://voidimpossible.com
  • Re: passing parameters to a metod using Eval()

    08-05-2007, 5:35 PM
    Answer
    • Loading...
    • HolyOne
    • Joined on 10-07-2005, 8:42 AM
    • Turkey
    • Posts 8

    Hi, can you please try this?

    <asp:LinkButton ID="LinkButton1" runat="server" onClick='OnDeleteComment(Int.Parse(Eval("ID").ToString() ) )' >Delete</asp:LinkButton>

    if this does not work try changing your function to this

    public static void OnDeleteComment(int commentid)
    {

    ...
    }

    Microsoft Rulez!
  • Re: passing parameters to a metod using Eval()

    08-05-2007, 8:02 PM
    Answer
    • Loading...
    • bcanonica
    • Joined on 12-08-2006, 9:11 PM
    • Philadelphia, PA
    • Posts 293

    Right direction method just can't be static since I have to call an external method from a base page I have.  Any other ideas?

     

    BC

    Remember to mark any post that is helpful as an answer and change posts status to Resolved to help others in the future.

    cheers,

    BC

    http://voidimpossible.com
  • Re: passing parameters to a metod using Eval()

    08-06-2007, 12:56 AM
    Answer
    • naveenj
    • Joined on 07-02-2007, 9:09 AM
    • India
    • Posts 608

    Hi bcanonica,

    Try this.

    aspx Page

    <asp:LinkButton ID="lnkDelete" runat="server"

    CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID") %>'

    OnCommand="OnDeleteComment"

    Text="Delete">

    </asp:LinkButton>

    aspx.cs Page

    public void OnDeleteComment(object sender,CommandEventArgs e)

    {

    string strDelete = e.CommandArgument.ToString();

    }

    Regards,

    Naveen

    Regards,
    Naveen

    Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question.
    View Blog
  • Re: passing parameters to a metod using Eval()

    08-08-2007, 11:02 AM
    • Loading...
    • bcanonica
    • Joined on 12-08-2006, 9:11 PM
    • Philadelphia, PA
    • Posts 293

    Really close it works, but for some reason when I run the application if gives me back the wrong parameter to the method?  I have the functionality I am looking for just need to remedy why the command arguement is passing the wrong value.  the value is sent correctly when I use a querystring, so I know my sql is correct.  Thank you so much I have been trying to get this one for weeks. 

     BC

    Remember to mark any post that is helpful as an answer and change posts status to Resolved to help others in the future.

    cheers,

    BC

    http://voidimpossible.com
Page 1 of 1 (7 items)
Microsoft Communities
Page view counter