我正在使用下面的代码创建数据网格
//Establishing the MySQL Connection
SqlConnection conn = new SqlConnection(@"Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-StudentMoneySaver-20160203040444.mdf;Initial Catalog=aspnet-StudentMoneySaver-20160203040444;Integrated Security=True");
string query;
SqlCommand SqlCommand;
SqlDataReader reader;
SqlDataAdapter adapter = new SqlDataAdapter();
//Open the connection to db
conn.Open();
//Generating the query to fetch the contact details
query = "SELECT EvtName, EvtType, EvtDescription, EvtDate, EvtVote FROM Events";
SqlCommand = new SqlCommand(query, conn);
adapter.SelectCommand = new SqlCommand(query, conn);
//execute the query
reader = SqlCommand.ExecuteReader();
//Assign the results
GridView1.DataSource = reader;
//Bind the data
GridView1.DataBind();
这是前端代码
<asp:DataGrid runat="server" ID="GridView1">
</asp:DataGrid>
目前,这是一个接一个地输出表中的每一行。我不确定如何将每一行输出到一个单独的超级电子管中,它的样式会更好一些。例如,EvtType可以是H1,事件描述H2等。任何帮助一如既往地非常感谢。我想分别显示每一行
答案 0 :(得分:1)
我建议使用<asp:Repeater
而不是DataGrid或GridView。然后,您可以完全控制每个项目的呈现方式。它看起来像这样:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
// Your HTML here, which will be repeated for each item
</ItemTemplate>
</asp:Repeater>