将网页划分为动态div标签 [英] Divide Webpage into dynamic div tags
问题描述
亲爱的,
我要求动态地将网页划分为多个div标签。
如何实现它?
我必须将图像放入div标签。
样本符合我的要求:
http:// epaper。 namasthetelangaana.com/epapermain.aspx?edcode=9&eddate=07/25/2012 [ ^ ]
i希望将页面分成持有的框,图片?
或
请建议我,如何实现这个目标?
感谢你..所有
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
推荐答案
一个简单的方法就是使用
A simple way to do this would be to use
System.Web.UI.HtmlControls.HtmlGenericControl newDIV = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
当然如果你使用System.Web.UI.HtmlControls它会很短。
另外请记住,这将是一个基本的div,你需要为它添加你想要的样式。但我建议,既然您使用的是ASP.NET,那么您可以通过向任何想要动态的区域添加ID和runat = server来简化这一过程。这将允许您直接在您的代码中使用它们。
例如在您的HTML中:
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:
<div id="testDiv" runat="server"></div>
现在你可以直接从代码中解决这个div根据需要添加图像或任何控件:
Now you can directly address this div from code behind and add images or any control as need:
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.
<%@ 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>
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);
}
}
}
这篇关于将网页划分为动态div标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!