繁体   English   中英

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

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

我正在使用下面的代码创建一个数据网格

 //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等。一如既往的任何帮助都将受到赞赏。 我想分别显示每一行

我建议使用<asp:Repeater代替DataGrid或GridView。 然后,您可以完全控制每个项目的呈现方式。 它看起来像这样:

<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