开发者

Can I pass more than 2 parameters or an array with onCommand event in asp.net?

开发者 https://www.devze.com 2023-04-10 01:09 出处:网络
the question is above and it is short. I am tryi开发者_运维百科ng to pass more parameters through a button in a repeater itemtemplateI would append the values to a string with a delimeter, like this:

the question is above and it is short. I am tryi开发者_运维百科ng to pass more parameters through a button in a repeater itemtemplate


I would append the values to a string with a delimeter, like this:

CommandArgument='<%# String.Format("{0}|{1}|{2}", Eval("Column1"), Eval("Column2"), Eval("Column3"))'%>    

When you get into the event handler, just split the string at the delimeter, like this:

var columnList = e.CommandArgument.Split('|');


The CommandArgument property takes a string. So you could put several values into that property in a comma separated format, e.g:

button.CommandArgument = "param1,param2,param3";

Then in the OnClick event handler, simply split the CommandArgument property:

var parameters = e.CommandArgument.Split(',');


I used a dumb way to walk around this problem.

pass all the stuff into CommandArgument and use string.split to get the parameter array.

CommandArgument='<%# Eval("PersonId") + ";" + Eval("PersonName") %>'

string[] paras = argu.Split(';');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号