Mike Marks
Mike Marks

Reputation: 10139

Passing multiple command arguments in an ImageButton control?

I'm designing a sort of hierarchical system, as follows:

Contract
Master Commodity
Commodity
Sub-Commodity
Part

Each one of these are on their own page (for now). The user starts out on the Contract.aspx page. If they want to see the Master Commodities for the contract they are currently on, they will click the "ImageButton" I have set up, and I pass in as a command argument the ContractID (CommandArgument='<%# Eval("ContractID")%>'). This works great- I get to my Master Commodity page with the Master Commodities filtered on the ContractID I passed in.

Here's my problem: Navigating from the Master Commodity page to the Commodity page will (I think) require passing in the ContractID (so we JUST see stuff for the contract we're on), AND the Master Commodity ID (so we JUST see the Commodities that are related to the Master Commodity). I've tried the following:

CommandArgument='<%# Eval("ContractID") + ',' + Eval("MComID")%>', but as you could probably expect, that doesn't work. If I can just do something like above and have a delimiter like the comma, I can go from there and make it work. Any suggestions???

Upvotes: 0

Views: 2377

Answers (3)

Griff
Griff

Reputation: 33

Mike,

borrowing form your own suggested solution you could have kept your ImageButton and used the following:

<%# string.Format("{0},{1}",Eval("value1"),Eval("value2"))%>

Late in the day but thought worth commenting for others following this thread.

Paul.

Upvotes: 2

Steven Ryssaert
Steven Ryssaert

Reputation: 1967

A suggestion is having a method in your code behind, which returns a well-formatted string

internal static string GetFormattedString(string sContractID, string sMcomID){
  return String.Format("{0},{1}", sContractID , sMcomID);
}

you could then Eval this function in your control. this way you keep the logic of formatting in your code behind, and only have to modify it there. This is a good practice if the information is used in different controls ( links ) on your front-end code.

Upvotes: 0

Mike Marks
Mike Marks

Reputation: 10139

What I decided to do is change my ImageButton to an "a href..." and use this as my href:

<%# string.Format("./Commodity.aspx?contractId={0}&MComID={1}, Eval("ContractId"), Eval("MComID"))%>

That way I can pass in all the information I need.

Upvotes: 0

Related Questions