How to create a Gridview

Asked

Viewed 197 times

0

The examples I saw on the net did not work, or were very personalized. I just want a simple table, with 4 columns that will be filled with data from a comic. The same will stay within a simple modal:

<div class="modal fade open" id="modalVersao" role="dialog" aria-labelledby="myModalLabel">
                        <div class="modal-dialog">

                            <div class="modal-content">
                                <div class="modal-header" >
                                    <button type="button" class="close" data-dismiss="modal"  aria-hidden="true">&times;</button>
                                    <h4 class="modal-title">
                                        <asp:Label ID="Label3" runat="server" Text="Gerenciar Versões"></asp:Label></h4>
                                </div>

                                <div class="modal-body">

         <!-- Quero o GRID aqui -->

                                                                                     </div>
                                <div class="modal-footer">
                                    //Botoes
                                </div>    
  • 1

    You cannot use a Datagridview and set your data as DATASOURCE ?

1 answer

1


EDIT

You can complete your task easily with a table HTML and a foreach (or for if you prefer). You can still do this with the asp:gridview or asp:repeater (also using table in the case of redepeater). An intermediary between the two is the asp:ListView.

An example with the Repeater:

<table>
    <asp:Repeater ID="Repeater" runat="server">
        <HeaderTemplate>
            <tr>
                <td>Código</td>
                <td>Nome</td>
                <td>Descrição</td>
                <td>Categoria</td>
                <td>Preço Unitário (R$)</td>
            </tr>
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td><%# Eval("Id") %></td>
                <td><%# Eval("Nome") %></td>
                <td><%# Eval("Descricao") %></td>
                <td><%# Eval("Categoria") %></td>
                <td><%# Eval("PrecoUnitario") %></td>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
            <tr>
                <td>Foo</td>
                <td>foo</td>
                <td>FOO</td>
                <td>fOO</td>
                <td>ooF</td>
            </tr>
        </FooterTemplate>
    </asp:Repeater>
</table>

In the C#:

List<Produto> produtos = ProdutoService.GetProdutos();
this.Repeater.DataSource = produtos;
this.Repeater.DataBind();

About the Repeater, you can find more information here: http://www.sitepoint.com/asp-net-repeater-control/

Another useful resource:

I hope this helps you, but feel free to share more information about it.

  • It can be an example with Repeater and a table, persistence is Entity framework, I already have the data. I want to list ,ID, name, etc., are 5 fields. A space for a checkbox would be interesting. , if you can post an example ai thanks, vlw.

  • Sorry for the delay, man. I ended up not being able to do it at home. I made a very simple example and edited the answer. See if it helps you. Thanks!

  • Thanks sorry I’m late too...

  • No problem. I hope the example has helped... If you need others let us know. Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.