动态控件用于在 ASP.NET 上创建链接按钮并分配属性

发布于 2025-01-02 12:01:40 字数 712 浏览 1 评论 0原文

我想在后面的代码中生成如下链接按钮。

<asp:LinkButton ID="lnkCustomize" OnClientClick="showDialog('editPerson')" Text="Customize"  CommandName="Customize"  CommandArgument='<%#Eval("type") + ";" + Eval("facility") + ";" + Eval("timestamp")%>runat="server"></asp:LinkButton>

这是我到目前为止所拥有的,但未能从争论中获取价值。感谢您的任何回复。

LinkButton link = new LinkButton();
link.Text = "Customize";
link.ID = "lnkCustomize";
double timestamp = ConvertToUnixTimestamp(leftstartTime1);
link.CommandArgument = Eval("type") + "," + Eval("facility") + "," + Eval("timestamp");
link.Command += new CommandEventHandler(DynamicClick);
link.OnClientClick = "showDialog('editPerson')";

I would like to generate the Link Button as below in code behind.

<asp:LinkButton ID="lnkCustomize" OnClientClick="showDialog('editPerson')" Text="Customize"  CommandName="Customize"  CommandArgument='<%#Eval("type") + ";" + Eval("facility") + ";" + Eval("timestamp")%>runat="server"></asp:LinkButton>

This is what I have so far but failed to retrieve value from arguements. Appreciate for any reply.

LinkButton link = new LinkButton();
link.Text = "Customize";
link.ID = "lnkCustomize";
double timestamp = ConvertToUnixTimestamp(leftstartTime1);
link.CommandArgument = Eval("type") + "," + Eval("facility") + "," + Eval("timestamp");
link.Command += new CommandEventHandler(DynamicClick);
link.OnClientClick = "showDialog('editPerson')";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱情眠于流年 2025-01-09 12:01:40

1.通过正确定义格式来修复

link.CommandArgument = "first_parameter_value_goes_here" + "," + "second_parameter_value_goes_here" + "," + "third_parameter_value_goes_here";

2。通过提取以下参数的所有值来修复

public void DynamicClick(object sender, EventArgs e)
    {
        var editLink = ((LinkButton)sender);
        string info = editLink.CommandArgument;
        string[] arg = new string[2];
        char[] splitter = { ',' };
        arg = info.Split(splitter);
        var var1 = arg[0];
        var var2 = arg[1];
        var var3 = arg[2];
    }

1. Fixed by having proper defined format

link.CommandArgument = "first_parameter_value_goes_here" + "," + "second_parameter_value_goes_here" + "," + "third_parameter_value_goes_here";

2. Fixed by extracting all the values of arguements as below

public void DynamicClick(object sender, EventArgs e)
    {
        var editLink = ((LinkButton)sender);
        string info = editLink.CommandArgument;
        string[] arg = new string[2];
        char[] splitter = { ',' };
        arg = info.Split(splitter);
        var var1 = arg[0];
        var var2 = arg[1];
        var var3 = arg[2];
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文