29/03/2006, 05:56
|
| | Fecha de Ingreso: octubre-2004
Mensajes: 55
Antigüedad: 20 años, 2 meses Puntos: 0 | |
TE indico un ejemplo. Espero q te sirva [SIZE="1"]<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb" Inherits="exporta.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:datagrid id="Datagrid" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 112px" runat="server"
BorderWidth="1" AlternatingItemStyle-BackColor="#eeeeee" CellSpacing="0" OnPageIndexChanged="DataGrid_Page"
PageSize="30" PagerStyle-PrevPageText="Anterior" PagerStyle-NextPageText="Siguiente" PagerStyle-HorizontalAlign="Right"
PagerStyle-Mode="NumericPages" AutoGenerateColumns="false" HeaderStyle-BackColor="#aaaadd"
CellPadding="1" GridLines="none" Font-Name="Verdana" BorderColor="black" Width="900px" AllowPaging="True"
Font-Size="XX-Small" Font-Names="Verdana" Height="764px">
<AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="N.I.F.">
<ItemTemplate>
<asp:label id="lblNIF" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "NIF") %>' Width="100px" Font-Name="Verdana" Font-Size="XX-Small"/>
</asp:label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>[/SIZE] ......
Lo de arriba sería parte del codigo de webForm.aspx en la vista html.
En WebForm.apsx.vb iría lago así Public Class WebForm2
Inherits System.Web.UI.Page
Private cartView As DataView
Protected WithEvents lblMsg As System.Web.UI.WebControls.Label
Private clsdb As New ClsDB
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents Datagrid As System.Web.UI.WebControls.DataGrid
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
cartView = Cart.DefaultView
If Not IsPostBack Then
cartView = Cart.DefaultView
BindGrid()
End If
End Sub
Private Sub BindGrid()
Datagrid.DataSource = cartView
Datagrid.DataBind()
End Sub
ReadOnly Property Cart() As DataTable
Get
Dim tmpData As DataTable
Dim dr As DataRow
If Session("Datos") Is Nothing Then
'crea DataTable
tmpData = New DataTable
'
tmpData.Columns.Add(New DataColumn("NIF", GetType(String)))
tmpData.Columns.Add(New DataColumn("Raz_Social", GetType(String)))
tmpData.Columns.Add(New DataColumn("Nombre_com", GetType(String)))
tmpData.Columns.Add(New DataColumn("Domicilio", GetType(String)))
tmpData.Columns.Add(New DataColumn("Localidad", GetType(String)))
tmpData.Columns.Add(New DataColumn("CP", GetType(String)))
tmpData.Columns.Add(New DataColumn("Provincia", GetType(String)))
tmpData.Columns.Add(New DataColumn("Telefono", GetType(String)))
tmpData.Columns.Add(New DataColumn("Fax", GetType(String)))
tmpData.Columns.Add(New DataColumn("Web", GetType(String)))
tmpData.Columns.Add(New DataColumn("_Mail", GetType(String)))
tmpData.Columns.Add(New DataColumn("Productos", GetType(String)))
Session("datos") = tmpData
clsdb.connectDB()
Dim rdrControl As System.Data.SqlClient.SqlDataReader
Dim cmd As SqlClient.SqlCommand
cmd = clsdb.getCMD
Dim st As String = "Select NIF, RAZ_SOCIAL, NOMBRE_COM, DOMICILIO, LOCALIDAD, CP, " & _
"PROVINCIA, TELEFONO, FAX, WEB, _MAIL, PRODUCTOS, Numero_de_ " & _
"FROM EMPRESAS WHERE nif LIKE '%" & Request.Params.Get("nif") & "%' "
If Request.Params.Get("razon").Length > 0 Then
st = st & "AND raz_social LIKE '%" & Request.Params.Get("razon") & "%' "
End If
If Request.Params.Get("web").Length > 0 Then
st = st & "AND web LIKE '%" & Request.Params.Get("web") & "%' "
End If
If Request.Params.Get("sector").Length > 0 Then
st = st & "AND sector_exc LIKE '%" & Request.Params.Get("sector") & "%' "
End If
If Request.Params.Get("prov").Length > 0 Then
st = st & "AND provincia LIKE '%" & Request.Params.Get("prov") & "%' "
End If
If Request.Params.Get("nombre").Length > 0 Then
st = st & "AND nombre_com LIKE '%" & Request.Params.Get("nombre") & "%' "
End If
If Request.Params.Get("dom").Length > 0 Then
st = st & "AND domicilio LIKE '%" & Request.Params.Get("dom") & "%' "
End If
If Request.Params.Get("cp").Length > 0 Then
st = st & "AND cp LIKE '%" & Request.Params.Get("cp") & "%' "
End If
If Request.Params.Get("fax").Length > 0 Then
st = st & "AND fax LIKE '%" & Request.Params.Get("fax") & "%' "
End If
If Request.Params.Get("tel").Length > 0 Then
st = st & "AND telefono LIKE '%" & Request.Params.Get("tel") & "%' "
End If
If Request.Params.Get("mail").Length > 0 Then
st = st & "AND _mail LIKE '%" & Request.Params.Get("mail") & "%' "
End If
If Request.Params.Get("prod").Length > 0 Then
st = st & "AND productos LIKE '%" & Request.Params.Get("prod") & "%' "
End If
cmd.CommandText = st
cmd.CommandType = CommandType.Text
rdrControl = cmd.ExecuteReader
With rdrControl
While .Read
dr = tmpData.NewRow()
dr(0) = .Item("NIF")
dr(1) = .Item("Raz_Social")
dr(2) = .Item("Nombre_com")
dr(3) = .Item("Domicilio")
dr(4) = .Item("Localidad")
dr(5) = .Item("CP")
dr(6) = .Item("Provincia")
dr(7) = .Item("Telefono")
dr(8) = .Item("Fax")
dr(9) = .Item("Web")
dr(10) = .Item("_Mail")
tmpData.Rows.Add(dr)
End While
End With
clsdb.disconnectDB()
Return tmpData
Else
Return Session("Datos")
End If
End Get
End Property
Sub DataGrid_Page(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
Datagrid.CurrentPageIndex = e.NewPageIndex
'Me.lblCurrentIndex.Text = DataGrid.CurrentPageIndex + 1
BindGrid()
End Sub
...
Espero que te sirva |