Click here to Skip to main content
15,905,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have already add dynamic LinkButton in run time under a Search Button event.
The Code is here:
C#
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:
C#
protected void btnSearch_Click(object sender, EventArgs e)
        {
            Page.Response.Redirect("Search.aspx?SearchKey=" + txtSearch.Text.ToString());
        }

So, in my summary I have three pages: 1. Default.aspx and 2. Search.aspx and 3. SearchResult.aspx. The Default.aspx page is my start up project page. Here I have a TextBox and a Button for search. My approach is write string in TextBox then click in the Button then under the event of the Button I run a SQL query to pick up data from database.
Now, suppose I got 3 results as 3 Article's Names and their 3 .pdf links. I can show the 3 Articles Name by adding 3 LinkButton with the LinkButton Text property. But, I am confused how to add 3 PDF link with these LinkButton and when I would click the LinkButton that will open another page named SearchResult.aspx with the specific pdf file in iframe control which is in SearchResult.aspx file as for example if I click LinkButton-1 than I will find in SearchResult.aspx file in iframe control with Pdf-1.


This is my problem. If anybody help me than I will very thankful to you. Please help me. Thank You!
Posted

1 solution

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

ASP.NET
<div id="MyPDFs"  runat="server">
            
</div>



and in the code behind

1. replace your for loop with this loop

C#
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 />";

      }


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

you may use Binding Expression as well

Thanks
 
Share this answer
 
v2
Comments
[no name] 21-Jan-13 3:49am    
+5!!!
Ahmed Mandur 21-Jan-13 9:03am    
Thanks Sisir :)
UL UL ALBAB 21-Jan-13 4:23am    
It's a great idea but, when I have click in this link I have to redirect SearchResult.aspx file then passing the pdf file link by querystring in the load_page of SearchResult.aspx. How can I do it?














h
Ahmed Mandur 21-Jan-13 9:03am    
ok, let me ask a question
> do u mean by your words that you want the link that will be redirected contain the Query string ?
and please would u write how could u receive the query string to show the PDF file in the Load of the page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900