Jump to content
Fórum Script Brasil
  • 0

Ordenando uma ListView através de um LinkButton



Boa tarde, preciso de uma ajuda.

É o seguinte, tenhum uma ListView e preciso ordená-la.

Porém preciso ordenar está ListView através de LinkButtons que estão fora dela.

Por exemplo:

Quando clico no LinkButton código, fazer com que a minha ListView ordene pela coluna do código.

Quando clico no LinkButton descrição, fazer com que a minha ListView ordene pela coluna da descrição.

Quando clico no LinkButton preço, fazer com que a minha ListView ordene pela coluna do preço.

Alguém sabe como me ajudar?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Exemplo (não dos melhores):

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void ResetBackGroundGridView()
        foreach (DataControlField c in GridView1.Columns)
            c.ItemStyle.BackColor = Color.Transparent;

    protected void btnNome_Click(object sender, EventArgs e)
        SqlDataSource1.SelectCommand = "SELECT [CustomerID], [CompanyName], [ContactName], [Phone] FROM [Customers] order by ContactName";
        GridView1.Columns[2].ItemStyle.BackColor = Color.Yellow;

    protected void btnCia_Click(object sender, EventArgs e)
        SqlDataSource1.SelectCommand = "SELECT [CustomerID], [CompanyName], [ContactName], [Phone] FROM [Customers] order by CompanyName";
        GridView1.Columns[1].ItemStyle.BackColor = Color.Yellow;

    protected void btnId_Click(object sender, EventArgs e)
        SqlDataSource1.SelectCommand = "SELECT [CustomerID], [CompanyName], [ContactName], [Phone] FROM [Customers] order by CustomerID";
        GridView1.Columns[0].ItemStyle.BackColor = Color.Yellow;

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server" 
            AutoGenerateColumns="False" DataKeyNames="CustomerID" 
                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" 
                    SortExpression="CustomerID" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" 
                    SortExpression="CompanyName" />
                <asp:BoundField DataField="ContactName" HeaderText="ContactName" 
                    SortExpression="ContactName" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:NWind %>" 
            SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [Phone] FROM [Customers]">
        <br />
        <br />
    &nbsp;<asp:Button ID="btnId" runat="server" Text="Ordenar Por Id" 
            onclick="btnId_Click" />
        <asp:Button ID="btnCia" runat="server" onclick="btnCia_Click" 
            Text="Ordenar por CIA" />
        <asp:Button ID="btnNome" runat="server" onclick="btnNome_Click" 
            Text="Ordenar por Nome" />

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Create New...