来自 Mysql DB C# 的旋转块引用
Rotating Blockquote from Mysql DB C#
这是我的数据库
CREATE TABLE IF NOT EXISTS `comments` (
`com_id` int(11) NOT NULL AUTO_INCREMENT,
`com_name` varchar(500) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`com_content` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`com_website` varchar(500) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`com_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`com_id`)
)
这是我的前端
<link href="js/jquery.bxslider.css" rel="stylesheet" type="text/css" />
<div class="container">
<asp:Label ID="lblComment" runat="server" Text=""/>
</div>
<script src="js/jquery.bxslider.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('.bxslider').bxSlider({
mode: 'horizontal',
slideMargin: 3,
auto: true
});
});
</script>
最后是我的后端
private void dispComments()
{
using (MySqlConnection conn = new MySqlConnection("server=localhost;database=test;uid=root;password="))
{
string query = "select * from comments order by com_date desc";
DataTable dt = new DataTable();
using (MySqlDataAdapter da = new MySqlDataAdapter(query, conn))
{
da.Fill(dt);
string comment = null;
for (int i = 0; i < dt.Rows.Count; i++)
{
//Message title
//news += "<div class='page-header' style='text-transform:capitalize;'><small>";
//news += dt.Rows[i]["com_content"].ToString();
//news +="</small></div>";
//Message Body
comment += "<ul class='bxslider'>";
comment += "<li>";
comment += "<blockquote>";
comment += dt.Rows[i]["com_content"].ToString();
comment += "<p style='text-align: right; margin-right: 20px;'>";
comment += dt.Rows[i]["com_name"].ToString();
comment += "</p></blockquote>";
comment += "</li>";
comment += "</ul>";
}
lblComment.Text = comment;
}
}
}
...我对我的评论有 3 条评论 table,所有这三个都已显示并且输出很好,除了它们往往单独出现,每次旋转只显示一个评论。我哪里出错了?请帮忙!!
<ul>
应该在 for
循环之外。当前代码在每次迭代下创建一个新的 <ul>
。所以对于每个 li
你有一个 ul
,并且对于每个 ul
滑块被初始化。
修改为这段代码,
string comment = null;
comment += "<ul class='bxslider'>";
for (int i = 0; i < dt.Rows.Count; i++)
{
comment += "<li>";
....
comment += "</li>";
}
comment += "</ul>";
这是我的数据库
CREATE TABLE IF NOT EXISTS `comments` (
`com_id` int(11) NOT NULL AUTO_INCREMENT,
`com_name` varchar(500) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`com_content` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`com_website` varchar(500) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`com_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`com_id`)
)
这是我的前端
<link href="js/jquery.bxslider.css" rel="stylesheet" type="text/css" />
<div class="container">
<asp:Label ID="lblComment" runat="server" Text=""/>
</div>
<script src="js/jquery.bxslider.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('.bxslider').bxSlider({
mode: 'horizontal',
slideMargin: 3,
auto: true
});
});
</script>
最后是我的后端
private void dispComments()
{
using (MySqlConnection conn = new MySqlConnection("server=localhost;database=test;uid=root;password="))
{
string query = "select * from comments order by com_date desc";
DataTable dt = new DataTable();
using (MySqlDataAdapter da = new MySqlDataAdapter(query, conn))
{
da.Fill(dt);
string comment = null;
for (int i = 0; i < dt.Rows.Count; i++)
{
//Message title
//news += "<div class='page-header' style='text-transform:capitalize;'><small>";
//news += dt.Rows[i]["com_content"].ToString();
//news +="</small></div>";
//Message Body
comment += "<ul class='bxslider'>";
comment += "<li>";
comment += "<blockquote>";
comment += dt.Rows[i]["com_content"].ToString();
comment += "<p style='text-align: right; margin-right: 20px;'>";
comment += dt.Rows[i]["com_name"].ToString();
comment += "</p></blockquote>";
comment += "</li>";
comment += "</ul>";
}
lblComment.Text = comment;
}
}
}
...我对我的评论有 3 条评论 table,所有这三个都已显示并且输出很好,除了它们往往单独出现,每次旋转只显示一个评论。我哪里出错了?请帮忙!!
<ul>
应该在 for
循环之外。当前代码在每次迭代下创建一个新的 <ul>
。所以对于每个 li
你有一个 ul
,并且对于每个 ul
滑块被初始化。
修改为这段代码,
string comment = null;
comment += "<ul class='bxslider'>";
for (int i = 0; i < dt.Rows.Count; i++)
{
comment += "<li>";
....
comment += "</li>";
}
comment += "</ul>";