Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / February 2005

Tip: Looking for answers? Try searching our database.

Dynamically populating a webform

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ben Ong - 17 Feb 2005 23:40 GMT
Hi,

i'm pretty new to the .NET framework and am looking for some help.  Is
there any way to dynamically create a number of hypertext links
dependant upon what is extracted from a database.  This is a lil
snippet of my code.

<script runat=server>
  for (int i =0 ; i < measureArray.Count; i++)
  {                                        </script>
<td>
  <asp:Label ID=measureArray[i].Name text=measureArray[i].Value />
</td>
<script runat=server>
  }
</script>

measureArray is an array of objects of type Measure(string name, in
value) whose values are extracted from a relational database.
i know this code wont work and i know it may look stupid.  I just wrote
it to try to give you guys a better idea of what im trying to do.
Thanks for the help.

-ben
anonymous@discussions.microsoft.com - 18 Feb 2005 22:51 GMT
Hi Ben
This is exactly what we mean by writing ASPNET Rendered
Controls. You can write your own control in ASPNET. Ok
here goes the logic, but before I start, I assume you are
a bit familiar with HTML and C#.

All you need to do is to first create a string which
stores HTML data equivalent to the 100 hyperlinks that
you wanna create, and then render this string on a HTML
Label. Find attached the sample code(not tested).

public class HyperlinkArray :
System.Web.UI.WebControls.Label
    {
        public HyperlinkArray()
        {
            //
            // TODO: Add constructor logic
here
            //
        }

        public System.Data.DataTable LabelData;

        protected override void OnPreRender
(EventArgs e)
        {
            HttpWriter htp = new HttpWriter();
            htp.Write(FormHtmlString());
            base.OnPreRender (e);
        }

        private string FormHtmlString()
        {
            string s = "";
            for(int i = 0;
i<LabelData.Columns.Count; i++)
            {
                s += "<a href=" +
LabelData.Rows[i]["Hyperlink"].ToString();
                s += "
CSSclass=\"HyperLinkClass\" >";
                s += ">" + LabelData.Rows
[i]["HyperlinkText"].ToString();
                s += "</a>";
            }

            return s;
        }

    }

Hope this helps...
Ramjee

>-----Original Message-----
>Hi,
[quoted text clipped - 7 lines]
>   for (int i =0 ; i < measureArray.Count; i++)
>   {                           
            </script>
><td>
>   <asp:Label ID=measureArray[i].Name text=measureArray[i].Value />
[quoted text clipped - 12 lines]
>
>.
Benjamin Ong - 23 Feb 2005 15:48 GMT
Hi Ramjee,

Thanks for the reply to my message.  While I was waiting for posts I
came up with another method of dynamically generating web controls in
ASP.NET.  I did some research and found out that by using the
placeholder web control I could generate any number of Web controls
dynamically. I haven't had a chance to try your solution yet but I was
wondering if you had any experience using the place holder web control,
and if so which solution should be used and why.

Thanks,

Ben

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.