我有一个表,要将表中的数据绑定到转发器中。但是我无法开始如何获得这个。这是我的设计HTML。我在中继器中需要它。
我想显示类似this的内容
我的HTML如下所示:-
<div class="Newsdivalign">
<div id="testMsg" class="popup">
<div class="popup-container">
<div class="popup-content">
<div class="popup-close js-popup-close modal-close">X</div>
<div>
<p class="popup-para">Recognised by the World Economic Forum as a Global Growth Company, 2014</p>
</div>
<div style="padding: 7px;">
<p class="NewsDate">News Posted: Jan 15, 2015 – 05:08 PM EST</p>
<p class="SStorypara">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been
the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley
of type and scrambled it to make a type specimen book. It has survived not only five centuries, but
also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
recently with desktop publishing software like Aldus PageMaker including versions of Lorem
Ipsum.
</p>
<p class="SStorypara">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been
the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley
of type and scrambled it to make a type specimen book. It has survived not only five centuries, but
also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
recently with desktop publishing software like Aldus PageMaker including versions of Lorem
Ipsum.
</p>
<p class="SStorypara">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been
the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley
of type and scrambled it to make a type specimen book. It has survived not only five centuries, but
also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
recently with desktop publishing software like Aldus PageMaker including versions of Lorem
Ipsum.
</p>
<p class="SStorypara">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been
the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley
of type and scrambled it to make a type specimen book. It has survived not only five centuries, but
also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
recently with desktop publishing software like Aldus PageMaker including versions of Lorem
Ipsum.
</p>
</div>
</div>
</div>
</div>
<div class="Newsdiv">
<p class="Newspara"><a href="#testMsg" class="modal-popup">Recognised by the World Economic Forum as a Global Growth Company, 2014</a></p>
<p class="NewsDate">News Posted: Jan 15, 2015 – 05:08 PM EST <span class="label">NGO1</span> <span class="label">NGO1</span> </p>
<p class="NewsDate1"><a href="#">Click here</a> to know more</p>
</div>
<div class="Newsdiv">
<p class="Newspara"><a href="Div1">Recognised by the World Economic Forum as a Global Growth Company, 2014</a></p>
<p class="NewsDate">News Posted: Jan 15, 2015 – 05:08 PM EST <span class="label">NGO1</span></p>
<p class="NewsDate1"><a href="#">Click here</a> to know more </p>
</div>
<div class="Newsdiv">
<p class="Newspara"><a href="#">Recognised by the World Economic Forum as a Global Growth Company, 2014</a></p>
<p class="NewsDate">News Posted: Jan 15, 2015 – 05:08 PM EST <span class="label">NGO1</span> <span class="label">NGO1</span></p>
<p class="NewsDate1"><a href="#">Click here</a> to know more</p>
</div>
<div class="Newsdiv">
<p class="Newspara"><a href="#">Recognised by the World Economic Forum as a Global Growth Company, 2014</a></p>
<p class="NewsDate">News Posted: Jan 15, 2015 – 05:08 PM EST <span class="label">NGO1</span></p>
<p class="NewsDate1"><a href="#">Click here</a> to know more</p>
</div>
<div class="Newsdiv">
<p class="Newspara"><a href="#">Recognised by the World Economic Forum as a Global Growth Company, 2014</a></p>
<p class="NewsDate">News Posted: Jan 15, 2015 – 05:08 PM EST <span class="label">NGO1</span> <span class="label">NGO1</span></p>
<p class="NewsDate1"><a href="#">Click here</a> to know more</p>
</div>
<div class="Newsdiv">
<p class="Newspara"><a href="#">Recognised by the World Economic Forum as a Global Growth Company, 2014</a></p>
<p class="NewsDate">News Posted: Jan 15, 2015 – 05:08 PM EST <span class="label">NGO1</span></p>
<p class="NewsDate1"><a href="#">Click here</a> to know more</p>
</div>
<div class="Newsdiv">
<p class="Newspara"><a href="#">Recognised by the World Economic Forum as a Global Growth Company, 2014</a></p>
<p class="NewsDate">News Posted: Jan 15, 2015 – 05:08 PM EST <span class="label">NGO1</span> <span class="label">NGO1</span></p>
<p class="NewsDate1"><a href="#">Click here</a> to know more</p>
</div>
<div class="Newsdiv">
<p class="Newspara"><a href="#">Recognised by the World Economic Forum as a Global Growth Company, 2014</a></p>
<p class="NewsDate">News Posted: Jan 15, 2015 – 05:08 PM EST <span class="label">NGO1</span></p>
<p class="NewsDate1"><a href="#">Click here</a> to know more</p>
</div>
<div class="Newsdiv">
<p class="Newspara"><a href="#">Recognised by the World Economic Forum as a Global Growth Company, 2014</a></p>
<p class="NewsDate">News Posted: Jan 15, 2015 – 05:08 PM EST <span class="label">NGO1</span> <span class="label">NGO1</span></p>
<p class="NewsDate1"><a href="#">Click here</a> to know more</p>
</div>
<div class="Newsdiv">
<p class="Newspara"><a href="#">Recognised by the World Economic Forum as a Global Growth Company, 2014</a></p>
<p class="NewsDate">News Posted: Jan 15, 2015 – 05:08 PM EST <span class="label">NGO1</span> <span class="label">NGO1</span></p>
<p class="NewsDate1"><a href="#">Click here</a> to know more</p>
</div>
<div class="pagination clearfix">
<a href="#">First</a>
<a href="#">«</a>
<a href="#">1</a>
<strong>2</strong>
<a href="#">3</a>
<a href="#">»</a>
<a href="#">Last</a>
</div>
</div>
请帮忙
我的更新代码:-
<asp:Repeater ID="rptNews" runat="server">
<ItemTemplate>
<div class="Newsdiv">
<p class="Newspara"><a href="#"><%#Eval("title")%></a></p>
<p class="NewsDate1"><a href="#">Click here</a> to know more</p>
</div>
</ItemTemplate>
</asp:Repeater>
背后的代码:
public void bindRepeater()
{
DataTable dtInfo = new DataTable();
dtInfo.Columns.Add("title");
DataRow dr;
for (int i = 0; i < 5; i++)
{
dr = dtInfo.NewRow();
dr["title"] = DateTime.Now.ToShortDateString();
dtInfo.Rows.Add(dr);
}
}
最佳答案
试试这个。将此中继器放置到您的设计中。
<asp:Repeater ID="rptNews" runat="server">
<ItemTemplate>
<div class="Newsdiv">
<p class="Newspara"><a href="#"><%#Eval("News_Title")%></a></p>
<p class="NewsDate">News Posted:<%#Eval("News_Time")%> <span class="label">NGO1</span> <span class="label">NGO1</span></p>
<p class="NewsDate1"><a href="#">Click here</a> to know more</p>
</div>
</ItemTemplate>
</asp:Repeater>
并据此从您的数据库中获取数据。在这里,我正在创建演示数据表来绑定转发器中的静态数据。您可以将其更改为数据库数据。
public void bindRepeater()
{
DataTable dtInfo = new DataTable();
dtInfo.Columns.Add("News_Title");
dtInfo.Columns.Add("News_Time");
DataRow dr;
for (int i = 0; i < 5; i++)
{
dr = dtInfo.NewRow();
dr["News_Time"] = DateTime.Now.ToShortDateString();
dr["News_Title"] = "Recongition statement";
dtInfo.Rows.Add(dr);
}
rptNews.DataSource = dtInfo;
rptNews.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindRepeater();
}
}