Html .NET和SQL:我需要构建自定义控件吗?
我正在VS 2013中使用默认的Web表单模板,其中一行有3个div:Html .NET和SQL:我需要构建自定义控件吗?,html,sql,.net,visual-studio-2013,Html,Sql,.net,Visual Studio 2013,我正在VS 2013中使用默认的Web表单模板,其中一行有3个div: <div class="col-md-4"> <h2>Get Paid</h2> <img src="Images/adp_logo.gif" class="img-responsive" alt="ADP" /> <p> Everybody wants to get paid! Just cl
<div class="col-md-4">
<h2>Get Paid</h2>
<img src="Images/adp_logo.gif" class="img-responsive" alt="ADP" />
<p>
Everybody wants to get paid! Just click on the "ADP" link to monitor or change your timesheet, benefits
information, 401K contributions, etc...
</p>
<p>
<a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301948">Go! »</a>
</p>
</div>
<div class="col-md-4">
<h2>Get Help</h2>
<asp:ImageButton ID="imgBtn2" runat="server" ImageUrl="~/Images/user_help.png" Height="100" />
<p>
Don't know how to do something? We can help! Click the image above to find answers about how to get a badge,
share your Outlook calendar, or make a great cup of coffee (okay, maybe not the last one, but you get the idea...)
</p>
<p>
<a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301949">Go! »</a>
</p>
</div>
<div class="col-md-4">
<h2>Find the People You Need</h2>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/find_icon.png" Height="100" />
<p>
You can easily find information about anybody that works at ERC. Just click and go!
</p>
<p>
<a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301950">Go! »</a>
</p>
</div>
得到报酬
每个人都想得到报酬!只需点击“ADP”链接即可监控或更改您的时间表、福利
信息、401K捐款等。。。
求助
找到你需要的人
我希望能够用数据库行中的信息填充这些div。例如,在我的数据库中,我有一个包含标题、图像、描述、链接和类别列的表。如果一行有一个“Featured”类别,它将用它的标题值填充第一个元素,用图像填充标记,等等
我是否需要构建一个自定义控件来实现这一点,或者我只是忽略了实现这一点的一种显而易见的方法
顺便说一句,Google Play商店就是我所要建模的,如果这有帮助的话
谢谢…正如David所说,.NET中继器控件非常适合您想要实现的目标。您只需添加一次html模板,它就会根据您的数据库查询和它将提取的条目数重复该模板 Html。请注意,将数据绑定到诸如“src”、“href”等属性时需要单引号:
<asp:Repeater ID="myRepeater" runat="server">
<ItemTemplate>
<div class="col-md-4">
<h2><%# Eval("Title") %></h2>
<img src='<%# Eval("Image") %>' class="img-responsive" alt="ADP" />
<p>
<%# Eval("Description") %>
</p>
<p>
<a class="btn btn-default" href='<%# Eval("Link") %>'>Go! »</a>
</p>
</div>
</ItemTemplate>
</asp:Repeater>
你只是在找一个
asp:Repeater
?@user2745258:我注意到你用了“ImageButton”。。这些是强制性的吗?服务器似乎没有绑定任何单击事件?我想我可能已经回答了你一半的问题。如果是这样,请告诉我,我将尽力帮助您获得所需的结果谢谢您的快速回复。我不认为图像按钮是强制性的,这正是我所设想的。我今晚会试试这个,明天早上再报告……效果很好。谢谢你们两位抽出时间来帮忙!太好了!这是我的荣幸。很高兴我能帮上忙
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) {
bindRepeater();
}
}
protected void bindRepeater() {
DatabaseEntities db = new DatabaseEntities();
var query = (from q in db.myTableName
where q.Category == "Featured"
select q);
if (query.Count() > 0)
{
myRepeater.DataSource = query.ToArray();
myRepeater.DataBind();
}
}