简体   繁体   中英

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???

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM