简体   繁体   English

在DataGrid Asp.Net C#中处理数据

[英]Manipulate data in a DataGrid Asp.Net C#

I'm creating a datagrid using the code below 我正在使用下面的代码创建一个数据网格

 //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();

and this is the front end code 这是前端代码

<asp:DataGrid runat="server" ID="GridView1">

             </asp:DataGrid>

At the moment, this is outputting each row within the table one after another. 目前,这是一个接一个地输出表中的每一行。 I'm not sure how I can output each row into a separate jumbotron with the it being styled a bit better. 我不确定如何将每一行输出到一个单独的巨型机中,其样式会更好一些。 For example, EvtType could he H1, Event Description H2 etc.. Any help as always is much appreciated. 例如,EvtType可以是H1,事件描述H2等。一如既往的任何帮助都将受到赞赏。 I'm looking to separately display each row 我想分别显示每一行

I'd suggest using an <asp:Repeater instead of a DataGrid or GridView. 我建议使用<asp:Repeater代替DataGrid或GridView。 Then you have complete control over how each item is rendered. 然后,您可以完全控制每个项目的呈现方式。 It would look something like this: 它看起来像这样:

<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
        // Your HTML here, which will be repeated for each item
    </ItemTemplate>
</asp:Repeater>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM