简体   繁体   English

在ImageButton控件中传递多个命令参数?

[英]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. 用户从Contract.aspx页面开始。 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")%>' ). 如果他们想要查看他们目前所在合同的Master Commodities,他们将点击我设置的“ImageButton”,然后作为命令参数传递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. 这非常有效 - 我进入了我的Master Commodity页面,主要商品已经过了我传入的ContractID。

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). 这是我的问题:从Master Commodity页面导航到Commodity页面(我认为)需要传递ContractID(所以我们只能看到我们所在的合同的东西),以及Master Commodity ID(所以我们只能看到与大宗商品有关的商品)。 I've tried the following: 我尝试过以下方法:

CommandArgument='<%# Eval("ContractID") + ',' + Eval("MComID")%>' , but as you could probably expect, that doesn't work. CommandArgument='<%# Eval("ContractID") + ',' + Eval("MComID")%>' ,但正如您可能预期的那样,这不起作用。 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: 从您自己建议的解决方案借用,您可以保留您的ImageButton并使用以下内容:

<%# 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: 我决定做的是将我的ImageButton更改为“a href ...”并将其用作我的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. 然后你可以在你的控件中Eval这个功能。 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. 如果在前端代码的不同控件(链接)中使用该信息,则这是一种很好的做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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