我有一个表格,我希望将表格中的数据绑定到转发器中。但我无法开始如何得到这个。这是我的设计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);
}
}
答案 0 :(得分:0)
试试这个。将这个转发器放到你的设计中。
<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>
并根据该数据从您的数据库中获取数据。在这里我创建demo数据表来绑定转发器中的静态数据。您可以将其更改为您的数据库数据。
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();
}
}