【问题标题】:how to do i make it do the href text will be changable by c#?我该怎么做才能使href文本可以通过c#更改?
【发布时间】:2022-01-14 16:46:42
【问题描述】:

我有字符串 list_name,我希望 href 链接文本是 list_name 中的字符串,而不是单词 list_name。我该怎么做?

 public void ShowButtonLists(DataTable table, int length)

        {
            for (int i = 0; i < length; i++)
            {
                string list_name = table.Rows[i].ToString();
                Response.Write("<td> <a href='ShowList.aspx?listname=" + list_name + "'>list_name</a></td> ");
                Response.Write("<br/>");
            }
        }

【问题讨论】:

  • 只记录开始/结束引号... listname='" + list_name + "'>" + list_name + "...
  • 也可以考虑利用字符串插值。引号不再是一个问题,并且在编码时读起来更好

标签: c# html asp.net


【解决方案1】:
 public void ShowButtonLists(DataTable table, int length)

        {
            for (int i = 0; i < length; i++)
            {
                string list_name = table.Rows[i].ToString();
                Response.Write("<td> <a href='ShowList.aspx?listname=" + list_name + "'>"+list_name +"</a></td> ");
                Response.Write("<br/>");
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2018-06-28
    相关资源
    最近更新 更多