Foros del Web » Programación para mayores de 30 ;) » .NET »

Ordenacion alfabetica con Gridview

Estas en el tema de Ordenacion alfabetica con Gridview en el foro de .NET en Foros del Web. Aqui les mando el ejemplo "Tigres" code behind Código: Imports System.Data Imports System.Data.Sqlclient Partial Class Default3 Inherits System.Web.UI.Page Private Sub Page_Load(ByVal sender As System.Object, ByVal ...
  #1 (permalink)  
Antiguo 21/04/2007, 11:19
 
Fecha de Ingreso: agosto-2006
Ubicación: en lima peru
Mensajes: 184
Antigüedad: 17 años, 8 meses
Puntos: 0
Ordenacion alfabetica con Gridview

Aqui les mando el ejemplo "Tigres"

code behind
Código:
Imports System.Data
Imports System.Data.Sqlclient
Partial Class Default3
    Inherits System.Web.UI.Page
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
            BindGrid()
        End If
    End Sub

    Sub BindGrid(Optional ByVal alpha As String = "")
        Dim connstr As String = "Integrated Security=SSPI;Initial Catalog=Northwind;Data Source=.\SQLEXPRESS"
        Dim cnn As New SqlConnection(connstr)
        Dim da As SqlDataAdapter
        If alpha = "" Then
            da = New SqlDataAdapter("select * from customers where companyname like 'A%'", cnn)
        Else
            da = New SqlDataAdapter("select * from customers where companyname like '" & LCase(alpha) & "%'", cnn)
        End If
        Dim ds As New DataSet()
        da.Fill(ds, "employees")
        GridView1.DataSource = ds
        GridView1.DataBind()
    End Sub

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "alpha" Then
            BindGrid(e.CommandArgument)
        End If
    End Sub
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
        If e.Row.RowType = 5 Then
            e.Row.Cells.Clear()
            Dim tc As New TableCell()
            tc.ColumnSpan = 2
            e.Row.Cells.Add(tc)
            Dim i As Integer
            For i = 65 To 65 + 25
                Dim l As New LinkButton
                Dim lc As New LiteralControl()
                lc.Text = " "
                l.Text = Chr(i)
                l.CommandName = "alpha"
                l.CommandArgument = Chr(i)
                tc.Controls.Add(l)
                tc.Controls.Add(lc)
            Next
        ElseIf e.Row.RowType = 1 Then
            e.Row.Cells.Clear()
            Dim tc As New TableCell()
            tc.ColumnSpan = 2
            e.Row.Cells.Add(tc)
            Dim i As Integer
            For i = 65 To 65 + 25
                Dim l As New LinkButton()
                Dim lc As New LiteralControl()
                lc.Text = " "
                l.Text = Chr(i)
                l.CommandName = "alpha"
                l.CommandArgument = Chr(i)
                tc.Controls.Add(l)
                tc.Controls.Add(lc)
            Next

        End If
    End Sub
End Class
pagina aspx

Código:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Página sin título</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" EmptyDataText=" " ShowFooter="True" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4">
            <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
            <RowStyle BackColor="White" ForeColor="#003399" Wrap="True" />
            <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
            <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
            <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
        </asp:GridView>
    
    </div>
    </form>
</body>
</html>
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:16.