Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to add so many pages in single webpage so i am using c# code behind this.
please find the below code and suggest how to add link

What I have tried:

string[] arrProcess = new[] { "1", "2", "3" };
                   int listItemIds = 1;

                  for (int ar = 0; ar < arrProcess.Length; ar++)
                  {
                      LinkButton lnk = new LinkButton();
                      lnk.ID = "lnk" + listItemIds;


                      lnk.Text = arrProcess[ar];

                      lnk.Click += new System.EventHandler(this.colorClick);
                      lnk.CommandArgument = Convert.ToString(ar); //LinkButton CommandArgument
                      lnk.CommandName = Convert.ToString(ar); //LinkButton CommanName

                      listItemIds++;
                      Place.Controls.Add(lnk); // Adding the LinkButton in PlaceHolder
                      Place.Controls.Add(new LiteralControl("<br />"));
                  }
Posted
Updated 20-Jun-19 1:19am
Comments
Maciej Los 20-Jun-19 6:58am    
And what's wrong with your code?
Member 14143173 20-Jun-19 7:04am    
how to give url in link button and so that it jumps to next page

1 solution

You can use something like this:
C#
void colorClick(Object sender, EventArgs e) //LinkButton_Click
{
   LinkButton lb = (LinkButton)sender;
   switch(lb.Name)
   {
       case "lnk1"
          //redirect to...
         break;

   }
}


For further details, please see: LinkButton.OnClick(EventArgs) Method (System.Web.UI.WebControls) | Microsoft Docs[^]
 
Share this answer
 
Comments
Member 14143173 20-Jun-19 7:21am    
sir there is 100 of pages so this logic is not applicable
Maciej Los 20-Jun-19 7:33am    
So, you have to define other method. You can use Dictionary object.
Member 14143173 20-Jun-19 7:34am    
is there any another way to add pages
Maciej Los 20-Jun-19 7:39am    
Do you have a list of those pages? Where are they stored?
Member 14143173 20-Jun-19 7:41am    
ya am stored in a array


{
F1 = Convert.ToString(Session["Substation_id"]) + "," + Substation_Name + "," + Convert.ToString(Session["Report_Id"]) + "," + (i - 1) + "," + strDate1.Trim() + "," + strDate2.Trim();
PageCol1.Controls.Add(new LiteralControl(" " + RowFontStart1 + " " + (i).ToString() + RowFontEnd1 + " "));
//arrProcess[i] = (" " + RowFontStart1 + " " + (i).ToString() + RowFontEnd1 + " ").ToString();

}

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