Stuart
Stuart

Reputation: 143

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. I'm looking to separately display each row

Upvotes: 0

Views: 101

Answers (1)

TheRotag
TheRotag

Reputation: 418

I'd suggest using an <asp:Repeater instead of a DataGrid or 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>

Upvotes: 1

Related Questions