在运行时在多个LinkBut​​ton中添加多个链接 [英] Add multiple link in multiple LinkButton in runtime

查看:56
本文介绍了在运行时在多个LinkBut​​ton中添加多个链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在搜索按钮事件下的运行时添加了动态LinkBut​​ton。

代码在这里:

I have already add dynamic LinkButton in run time under a Search Button event.
The Code is here:

for (int i = 0; i < db.dataSet.Tables["searchResult"].Rows.Count; i++)
            {
                LinkButton lnkSearch = new LinkButton();
                lnkSearch.Text = txtSearch.Text.ToString();
                lnkSearch.ID = "label" + i.ToString();
                //lnkSearch.AccessKey = db.dataSet.Tables["searchResult"].Rows[i][0].ToString();
                
                this.UpdatePanel1.ContentTemplateContainer.Controls.Add(lnkSearch);
                this.UpdatePanel1.ContentTemplateContainer.Controls.Add(new LiteralControl("<br/>"));
}



当我点击搜索按钮时,此工作正常。

代码在这里:


This working good when I am click in a search Button.
The Code is here:

protected void btnSearch_Click(object sender, EventArgs e)
        {
            Page.Response.Redirect("Search.aspx?SearchKey=" + txtSearch.Text.ToString());
        }



因此,在我的摘要中我有三个页面:1。Default.aspx和2. Search.aspx和3. SearchResult.aspx 。 Default.aspx页面是我的启动项目页面。这里我有一个TextBox和一个用于搜索的按钮。我的方法是在TextBox中编写字符串然后单击Button然后在Button的事件下运行SQL查询以从数据库中获取数据。

现在,假设我得到3个结果作为3条文章的名字和3个.pdf链接。我可以通过添加3个LinkBut​​ton和LinkBut​​ton Text属性来显示3篇文章名称。但是,我很困惑如何添加3个PDF链接与这些LinkBut​​ton,当我点击LinkBut​​ton将打开另一个名为SearchResult.aspx的页面与iframe控件中的特定pdf文件,在SearchResult.aspx文件中,例如,如果我单击LinkBut​​ton-1,然后在使用Pdf-1的iframe控件中的SearchResult.aspx文件中找到。




这是我的问题。如果有人帮助我,我会非常感谢你。请帮我。谢谢!

推荐答案



有一个非常简单的解决方案,但不是最佳解决方案。

您可以使用HTML格式进行操作。



在设计页面中



1.添加将包含你的链接的Runat服务器DIV



Hi,
There is a very simple solution but not the optimum solution .
You may use a HTML Formatting to do it .

In the design page

1. add Runat server DIV which will contain your Links

<div id="MyPDFs"  runat="server">
            
</div>







和后面的代码



1.用这个循环替换你的for循环






and in the code behind

1. replace your for loop with this loop

for (int i = 0; i < db.dataSet.Tables["searchResult"].Rows.Count; i++)
      {
          string PDFlink = string.Empty;  //Replace this with the link of the PDF
          string PDFTitle = string.Empty; //Replace this with the title of hte PDF
          MyPDFs.InnerHtml += "<a href='" + PDFlink + "'>" + PDFTitle + "</a><br />";

      }





正如我告诉你的那样,它不是最佳的但它的确有效



你也可以使用Binding Expression



谢谢



and as i told u it''snot the optimum but it works

you may use Binding Expression as well

Thanks


这篇关于在运行时在多个LinkBut​​ton中添加多个链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆