WEB PART:PAGINAR UN DATAGRID

29/11/2004 - 22:40 por crifistian | Informe spam
Hola a todos:

esto es urgente!!!!
hago un filtro y lo q se muestre en el datagrid es una cantidad
innumerable de filas. necesito repaginar ese datagrid
primero lo hice en una pagina aspx pero no se como ponerlo en un web part
ademas en una pagina aspx le das click derecho al datagrid y entras a la
propiedades de esta...como se haria para un web part

un favor...esta vez contestenme !!!!

Gracias

Preguntas similare

Leer las respuestas

#1 crifistian
29/11/2004 - 23:21 | Informe spam
en un momento de inspiracion me salio asi q se los paso por si alguien
quieres,como dicen cuando llueve,llueve para todos
lo q les aconsejo es q copien este codigo en vs 2003 y alli recien lo
analizan...bye
-
Dim WithEvents dgCustomer As DataGrid
Dim lbError As Label = Nothing
Dim lbCustomerId As Label = Nothing
Dim lbCustomerName As Label = Nothing
Dim lbCustomerAddress As Label = Nothing
Dim lbCustomerPhone As Label = Nothing
Dim lbCustomerDate As Label = Nothing
Protected Overrides Sub CreateChildControls()

With opnCod
opnCod = New RadioButton
.AutoPostBack = True
.Text = "Codigo"
.TextAlign = TextAlign.Right
.GroupName = "Grupo"
Controls.Add(opnCod)
End With

With opnNom
opnNom = New RadioButton
.Text = "Nombres"
.AutoPostBack = True
.TextAlign = TextAlign.Right
.GroupName = "Grupo"
Controls.Add(opnNom)
End With

'Lable that display error messages
lbError = New Label
lbError.Visible = False
lbError.ForeColor = System.Drawing.Color.Red
Controls.Add(lbError) 'Add to controls list

'Lable that display Customer Id
lbCustomerId = New Label
lbCustomerId.Visible = False
Controls.Add(lbCustomerId) ' //Add to controls list

'Lable that display Customer Name
lbCustomerName = New Label
lbCustomerName.Visible = False
Controls.Add(lbCustomerName) ' //Add to controls list

'//Lable that display Customer Address
lbCustomerAddress = New Label
lbCustomerAddress.Visible = False
Controls.Add(lbCustomerAddress) ' //Add to controls list

'Lable that display Customer Phone
lbCustomerPhone = New Label
lbCustomerPhone.Visible = False
Controls.Add(lbCustomerPhone) ' //Add to controls list

'//Lable that display Register date
lbCustomerDate = New Label
lbCustomerDate.Visible = False
Controls.Add(lbCustomerDate) ' //Add to controls list

'// Create the data grid
dgCustomer = New DataGrid
Dim newColumn As BoundColumn '//Creating BoundColumn to hold data
Dim ButtonColumnSelect As ButtonColumn ' //Creating ButtonColumn
to select data

'//Adding properties to the datagrid
dgCustomer.AllowPaging = True
dgCustomer.PagerStyle.Mode = PagerMode.NumericPages
dgCustomer.PageSize = 6

dgCustomer.HeaderStyle.Font.Bold = False
dgCustomer.HeaderStyle.BackColor = System.Drawing.Color.Black
dgCustomer.HeaderStyle.ForeColor = System.Drawing.Color.White
dgCustomer.HeaderStyle.Wrap = False
dgCustomer.HorizontalAlign = HorizontalAlign.Center
dgCustomer.GridLines = System.Web.UI.WebControls.GridLines.Both
dgCustomer.SelectedItemStyle.BackColor System.Drawing.Color.YellowGreen

' dgCustomer.SelectedIndexChanged += new
EventHandler(this.dgCustomer_SelectedIndexChanged );
dgCustomer.AutoGenerateColumns = False

'// Define grid columns

' //Creating select ButtonColumn
ButtonColumnSelect = New ButtonColumn
ButtonColumnSelect.ButtonType = ButtonColumnType.LinkButton
ButtonColumnSelect.CommandName = "Select"
ButtonColumnSelect.Text = "Select"
ButtonColumnSelect.Visible = True
dgCustomer.Columns.Add(ButtonColumnSelect) ' //Add column to
DataGrid

' //Creating CustomerID BoundColumn
newColumn = New BoundColumn
newColumn.DataField = "CustomerID"
newColumn.HeaderText = "Customer ID"
newColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center
dgCustomer.Columns.Add(newColumn) ' //Add column to DataGrid

'//Creating CustomerName BoundColumn
newColumn = New BoundColumn
newColumn.DataField = "CompanyName"
newColumn.HeaderText = "Customer Name"
newColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center
dgCustomer.Columns.Add(newColumn) ' //Add column to DataGrid

'//Creating Address BoundColumn
newColumn = New BoundColumn
newColumn.DataField = "Address"
newColumn.HeaderText = "Customer Address"
newColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center
dgCustomer.Columns.Add(newColumn) ' //Add column to DataGrid

'Creating PhoneNumber BoundColumn
newColumn = New BoundColumn
newColumn.DataField = "Phone"
newColumn.HeaderText = "Phone Number"
'// newColumn.DataFormatString = "{0:d}"
newColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center
dgCustomer.Columns.Add(newColumn) ' //Add column to DataGrid

'//Creating RegistedDate BoundColumn
newColumn = New BoundColumn
newColumn.DataField = "Country"
newColumn.HeaderText = "Country"
'//newColumn.DataFormatString = "{0:d}"
newColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center
dgCustomer.Columns.Add(newColumn) ' //Add column to DataGrid

Controls.Add(dgCustomer) ' //Add the DataGrid to controls list

' //Load the data to the DataGrid
If Not Page.IsPostBack Then
LoadCustomer()
Else
dgCustomer.CurrentPageIndex = 0
LoadCustomer()

End If

End Sub
Sub LoadCustomer()

Try


Dim dtCustomerTable As DataTable = New DataTable '//Create
DataTable
Dim fila As DataRow


'//Add columns to DataGrid
dtCustomerTable.Columns.Add(New DataColumn("CustomerID",
GetType(String)))
dtCustomerTable.Columns.Add(New DataColumn("CompanyName",
GetType(String)))
dtCustomerTable.Columns.Add(New DataColumn("Address",
GetType(String)))
dtCustomerTable.Columns.Add(New DataColumn("Phone",
GetType(String)))
dtCustomerTable.Columns.Add(New DataColumn("Country",
GetType(String)))

Dim cn As SqlConnection = New SqlConnection("integrated
security=SSPI;data source=CROJAS;persist security info=True;initial
catalog=Northwind")
Dim cmd As SqlCommand = New SqlCommand("select
CustomerId,CompanyName,Address,Phone,Country from customers", cn)
cmd.CommandType = CommandType.Text

cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()

While (dr.Read)
fila = dtCustomerTable.NewRow()
fila(0) = dr.GetString(0)
fila(1) = dr.GetString(1)
fila(2) = dr.GetString(2)
fila(3) = dr.GetString(3)
fila(4) = dr.GetString(4)

dtCustomerTable.Rows.Add(fila)
End While


dgCustomer.Enabled = True
dgCustomer.DataSource = dtCustomerTable
'//Bind the DataGrid
dgCustomer.DataBind()
cn.Close()
cmd.Dispose()

Catch ex As Exception

'//Displaying the Exceptions.
lbError.Text = ex.Message
lbError.Visible = True
Return
End Try
End Sub

Protected Overrides Sub RenderWebPart(ByVal output As
System.Web.UI.HtmlTextWriter)
output.Write(SPEncode.HtmlEncode([Text]))

output.RenderBeginTag("table")

output.RenderBeginTag("tr") 'Add a row
output.RenderBeginTag("td") ' Add a cell
dgCustomer.RenderControl(output) 'Render DataGrid
output.RenderEndTag() 'End of the cell tag
output.RenderEndTag() 'End of the row tag

output.RenderBeginTag("tr") 'Add a row
output.AddStyleAttribute(HtmlTextWriterStyle.Height, "5")
output.RenderBeginTag("td") ' Add a cell
output.RenderEndTag() 'End of the cell tag
output.RenderEndTag() 'End of the row tag

output.RenderBeginTag("tr") 'Add a row
output.AddStyleAttribute(HtmlTextWriterStyle.FontWeight, "bold")
output.RenderBeginTag("td") ' Add a cell
output.Write("Selected Customer Details")
output.RenderEndTag() 'End of the cell tag
output.RenderEndTag() 'End of the row tag

output.RenderBeginTag("tr") 'Add a row
output.RenderBeginTag("td") ' Add a cell
output.Write("Customer Id: ")
lbCustomerId.RenderControl(output) 'Render Customer Id lable
output.RenderEndTag() 'End of the cell tag
output.RenderEndTag() 'End of the row tag

output.RenderBeginTag("tr") 'Add a row
output.RenderBeginTag("td") ' Add a cell
output.Write("Customer Name: ")
lbCustomerName.RenderControl(output) 'Render Customer Name lable
output.RenderEndTag() 'End of the cell tag
output.RenderEndTag() 'End of the row tag

output.RenderBeginTag("tr") 'Add a row
output.RenderBeginTag("td") ' Add a cell
output.Write("Customer Address: ")
lbCustomerAddress.RenderControl(output) 'Render Customer Adress
lable
output.RenderEndTag() 'End of the cell tag
output.RenderEndTag() 'End of the row tag

output.RenderBeginTag("tr") 'Add a row
output.RenderBeginTag("td") ' Add a cell
output.Write("Customer Phone: ")
lbCustomerPhone.RenderControl(output) 'Render Customer Phone lable
output.RenderEndTag() 'End of the cell tag
output.RenderEndTag() 'End of the row tag

output.RenderBeginTag("tr") 'Add a row
output.RenderBeginTag("td") ' Add a cell
output.Write("Pais: ")
lbCustomerDate.RenderControl(output) 'Render Register date lable
output.RenderEndTag() 'End of the cell tag
output.RenderEndTag() 'End of the row tag

output.RenderBeginTag("tr") 'Add a row
output.RenderBeginTag("td") ' Add a cell
lbError.RenderControl(output) 'Render error lable
output.RenderEndTag() 'End of the cell tag
output.RenderEndTag() 'End of the row tag

output.RenderEndTag()
End Sub


Private Sub dgCustomer_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles dgCustomer.SelectedIndexChanged
'//Adding selected customer Id to the lable
lbCustomerId.Visible = True
lbCustomerId.Text = dgCustomer.SelectedItem.Cells(1).Text

'Adding selected customer Name to the lable
lbCustomerName.Visible = True
lbCustomerName.Text = dgCustomer.SelectedItem.Cells(2).Text

'Adding selected customer Address to the lable
lbCustomerAddress.Visible = True
lbCustomerAddress.Text = dgCustomer.SelectedItem.Cells(3).Text

'//Adding selected customer Phon number to the lable
lbCustomerPhone.Visible = True
lbCustomerPhone.Text = dgCustomer.SelectedItem.Cells(4).Text

'//Adding selected Register date to the lable
lbCustomerDate.Visible = True
lbCustomerDate.Text = dgCustomer.SelectedItem.Cells(5).Text
End Sub


Private Sub dgCustomer_PageIndexChanged(ByVal source As Object, ByVal
e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
dgCustomer.PageIndexChanged
dgCustomer.CurrentPageIndex = e.NewPageIndex
LoadCustomer()

End Sub






Christian wrote:

Hola a todos:

esto es urgente!!!!
hago un filtro y lo q se muestre en el datagrid es una cantidad
innumerable de filas. necesito repaginar ese datagrid
primero lo hice en una pagina aspx pero no se como ponerlo en un web part
ademas en una pagina aspx le das click derecho al datagrid y entras a la
propiedades de esta...como se haria para un web part

un favor...esta vez contestenme !!!!

Gracias
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida