Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
3.86/5 (4 votes)
See more:
Dear,

I have the requirement to divide a webpage into multiple div tags dynamically.
How to achieve it?

I have to place images to in the div tags.

sample for my requirement:

http://epaper.namasthetelangaana.com/epapermain.aspx?edcode=9&eddate=07/25/2012[^]

i want to divide the page into boxes which holds, the images?

or

please suggest me, how to achieve this?

thanking you..all
Posted
Updated 24-Jul-12 23:47pm
v2

A simple way to do this would be to use

C#
System.Web.UI.HtmlControls.HtmlGenericControl newDIV = new System.Web.UI.HtmlControls.HtmlGenericControl("div");


Of course if you are "using" System.Web.UI.HtmlControls it would be much short.

Also keep in mind this would be a basic div and you would need to add the styling to it that you would want. I would suggest however that since you are using ASP.NET you could make this easier by adding IDs and "runat=server" to any areas that you want to be dynamic. This would allow you to use them directly in your code behind.

For example in your HTML:
ASP.NET
<div id="testDiv" runat="server"></div>


Now you can directly address this div from code behind and add images or any control as need:
C#
Image img = new Image();
img.ImageUrl = "~/imagelocation/image.jpg";
img.AlternateText = "image";
testDiv.Controls.Add(img);


Again, you would want to add image sizing etc depending on your needs. I am not sure exactly what you are going for but this should get you started.
 
Share this answer
 
XML
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

    <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>


</asp:Content>





C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Panel div1 = new Panel{ ID = "div1",CssClass="div1style" };
            Image img = new Image { ImageUrl = "~/images/pic.jpg", AlternateText = "Blah" };
            div1.Controls.Add(img);
            PlaceHolder1.Controls.Add(div1);
        }
    }
}
 
Share this answer
 

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