Leonardo_Augusto Posted April 11, 2015 at 11:06 PM Report Share #581072 Posted April 11, 2015 at 11:06 PM (edited) Olá! Estou a criar um sistema que mostre na página inicial do site os 5 registros mais recentes do BD em uma LISTA . Basicamente a tabela do Banco de dados é assim: ID Artigo URL Eu preciso carregar os ultimos cinco (5) dados em uma lista e que seja possivel clicar nestes links e redirecionar para a url. Eu tenho a consulta SELECT TOP [ ] .... FROM [TABELA] mas não tenho ideia de como criar uma lista do tipo : ÚLTIMAS POSTAGENS. Edited April 11, 2015 at 11:09 PM by Leonardo_Augusto Link to comment Share on other sites More sharing options...
snis Posted April 11, 2015 at 11:12 PM Report Share #581073 Posted April 11, 2015 at 11:12 PM podes fazer select * from [tabela] order by id desc limit 5 depois criar evento de forma abrir pagina (por exemplo) com o id do registo Link to comment Share on other sites More sharing options...
Leonardo_Augusto Posted April 11, 2015 at 11:57 PM Author Report Share #581075 Posted April 11, 2015 at 11:57 PM (edited) Basicamente quero preencher o componente abaixo com os 5 ultimos dados do banco de dados e que tenha Hyperlink <form id="form1" runat="server"> <div> <asp:BulletedList ID="BulletedList1" runat="server"> <asp:ListItem>Dados do BD</asp:ListItem> <asp:ListItem>Dados do BD</asp:ListItem> <asp:ListItem>Dados do BD</asp:ListItem> <asp:ListItem>Dados do BD</asp:ListItem> <asp:ListItem>Dados do BD</asp:ListItem> </asp:BulletedList> </div> </form> Edited April 11, 2015 at 11:58 PM by Leonardo_Augusto Link to comment Share on other sites More sharing options...
snis Posted April 12, 2015 at 12:31 AM Report Share #581077 Posted April 12, 2015 at 12:31 AM (edited) tens que primeiro criar o teu dataSource, por exemplo <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=XXX;Initial Catalog=XXX;Persist Security Info=True;User ID=XXX;Password=XXX" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [tabela] order by ID LIMIT 5"> </asp:SqlDataSource> depois <form id="form1" runat="server"> <div> <asp:BulletedList ID="BulletedList1" runat="server"> <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"> <asp:ListItem><a href="<%# DataBinder.Eval(Container.DataItem, "URL") %>"><%# DataBinder.Eval(Container.DataItem, "ID") %><%# DataBinder.Eval(Container.DataItem, "Artigo") %></a></asp:ListItem> </asp:Repeater> </asp:BulletedList> </div> nao testei , mas a ideia está ai Edited April 12, 2015 at 11:05 AM by apocsantos geshi Link to comment Share on other sites More sharing options...
Leonardo_Augusto Posted April 12, 2015 at 06:20 PM Author Report Share #581104 Posted April 12, 2015 at 06:20 PM (edited) Estou a tentar assim : Private Function GetData() As DataSet Dim query As String = "SELECT top 5 * FROM Articles" Dim cmd As New SqlCommand(query) Using sda As New SqlDataAdapter() cmd.Connection = Conexao.Conectar sda.SelectCommand = cmd Using ds As New DataSet() sda.Fill(ds) Return ds End Using End Using End Function If Not IsPostBack Then ListView1.DataSource = Me.GetData() ListView1.DataBind() End If <asp:ListView ID="ListView1" runat="server" GroupItemCount="3" GroupPlaceholderID="groupPlaceHolder1" ItemPlaceholderID="itemPlaceHolder1"> <LayoutTemplate> <table> <asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder> </table> </LayoutTemplate> <GroupTemplate> <tr> <asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder> </tr> </GroupTemplate> <ItemTemplate> <td> <table border="1" style="width: 200px; height: 100px; border: dashed 2px #04AFEF; background-color: #B0E2F5"> <tr> <td> <b>Post: </b><span class="Post"> <%# Eval("Article")%></span><br /> <b>Descrição: </b><span class="Article"> <%# Eval("Descricao")%></span><br /> <b>Leia Mais: </b><span class="Descricao"> <%# DataBinder.Eval(Container.DataItem, "Url")%>"</span><br /> </td> </tr> </table> </td> </ItemTemplate> </asp:ListView> Mas estou recebendo o erro: Referência de objeto não definida para uma instância de um objeto. Edited April 12, 2015 at 06:21 PM by Leonardo_Augusto Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now