我正在尝试编写一个项目来显示MMABooks
数据库中2个表的一些数据。这些代码在C#中工作,但它们在ASP.Net中不起作用。实际上,它什么都不做,我没有任何错误!为什么?有什么问题?
string connectionString = "Data Source=localhost\\SqlExpress;" +
"Initial Catalog=MMABooks;Integrated Security=True";
SqlConnection connection = new SqlConnection(connectionString);
string selectStatement = "SELECT Customers.Name, Customers.City, States.StateName " +
"FROM Customers " +
"INNER JOIN States " +
"ON Customers.State = States.StateCode " +
"WHERE Name LIKE @Name";
SqlCommand SelectCommand = new SqlCommand(selectStatement, connection);
SelectCommand.Parameters.AddWithValue("@Name", TextBox1.Text.Trim() + "%");
connection.Open();
var dataAdapter = new SqlDataAdapter(SelectCommand);
DataTable dt = new DataTable();
dataAdapter.Fill(dt);
GridView1.DataSource = dt;
答案 0 :(得分:3)
您需要ASP.NET中的GridView1.DataBind()
将数据源绑定到最后一行之后的GridView
。
GridView1.DataSource = dt;
GridView1.DataBind();
答案 1 :(得分:0)
在<ul>
<li><img alt="" class="icon-grid" src="https://cdn-accept-www.enfocus.com/sites/combell-accept-www.enfocus.com/files/media/product-pages/pitstop-pro/low-resolution.png"></li>
<li><img alt="" class="icon-grid" src="https://cdn-accept-www.enfocus.com/sites/combell-accept-www.enfocus.com/files/media/product-pages/pitstop-pro/low-resolution.png"></li>
<li><img alt="" class="icon-grid" src="https://cdn-accept-www.enfocus.com/sites/combell-accept-www.enfocus.com/files/media/product-pages/pitstop-pro/low-resolution.png"></li>
<li><img alt="" class="icon-grid" src="https://cdn-accept-www.enfocus.com/sites/combell-accept-www.enfocus.com/files/media/product-pages/pitstop-pro/low-resolution.png"></li>
<li><img alt="" class="icon-grid" src="https://cdn-accept-www.enfocus.com/sites/combell-accept-www.enfocus.com/files/media/product-pages/pitstop-pro/low-resolution.png"></li>
<li><img alt="" class="icon-grid" src="https://cdn-accept-www.enfocus.com/sites/combell-accept-www.enfocus.com/files/media/product-pages/pitstop-pro/low-resolution.png"></li>
<li><img alt="" class="icon-grid" src="https://cdn-accept-www.enfocus.com/sites/combell-accept-www.enfocus.com/files/media/product-pages/pitstop-pro/low-resolution.png"></li>
<li><img alt="" class="icon-grid" src="https://cdn-accept-www.enfocus.com/sites/combell-accept-www.enfocus.com/files/media/product-pages/pitstop-pro/low-resolution.png"></li>
</ul>
GridView1.DataSource = dt;
GridView1.DataSource = dt;