Jump to content
Fórum Script Brasil
  • 0

Ordenando uma ListView através de um LinkButton


ricardoespiridiao
 Share

Question

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";
        ResetBackGroundGridView();
        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";
        ResetBackGroundGridView();
        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";
        ResetBackGroundGridView();
        GridView1.Columns[0].ItemStyle.BackColor = Color.Yellow;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" 
            AutoGenerateColumns="False" DataKeyNames="CustomerID" 
            DataSourceID="SqlDataSource1">
            <Columns>
                <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" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:NWind %>" 
            SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [Phone] FROM [Customers]">
        </asp:SqlDataSource>
        <br />
        <br />
    &nbsp;<asp:Button ID="btnId" runat="server" Text="Ordenar Por Id" 
            onclick="btnId_Click" />
    &nbsp;&nbsp;
        <asp:Button ID="btnCia" runat="server" onclick="btnCia_Click" 
            Text="Ordenar por CIA" />
&nbsp;&nbsp;
        <asp:Button ID="btnNome" runat="server" onclick="btnNome_Click" 
            Text="Ordenar por Nome" />
    </div>
    </form>
    <p>
        &nbsp;</p>
</body>
</html>

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.

Guest
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.

 Share



  • Forum Statistics

    • Total Topics
      150.2k
    • Total Posts
      647.4k
×
×
  • Create New...