Hola, he conseguido crear diferentes web parts. Pero
cuando intento crear un webpart que accede a una base de
datos y muestro los datos en un DataGrid no llega a
importarlo (consigo cargarlo pero al arrastralo)se me va
a :
"
http://asweb03:82/_layouts/3082/error.aspx?
ErrorID=SpecificWebPartError&ErrorIDArgs=WebPart1&ErrorLink
TextID=MaintenancePageLinkText&ErrorLinkDescriptionID=Maint
enancePageDescription&ErrorLinkNavigateUrl=spcontnt%2Easpx%
3FPageView%3DShared%26url%3D%252fdefault%2Easpx%253fMode%
253dEdit%2526PageView%253dShared"
y aparece lo siguiente:
Error:
El elemento Web "WebPart1" parece estar causando un
problema.
Página de mantenimiento de elementos Web: Si tiene
permiso, puede usar esta página para deshabilitar
temporalmente elementos Web o quitar la configuración
personal. Para obtener más información, póngase en
contacto con el administrador del sitio.
Solucionar problemas de Windows SharePoint Services.
Os pongo el código del Webpart:
sing System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Utilities;
using System.Web.UI.HtmlControls;using System.Data;
using System.Data.SqlClient;
namespace Ultimo
{
/// <summary>
/// Description for WebPart1.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WebPart1 runat=server></
{0}:WebPart1>"),
XmlRoot(Namespace="Ultimo")]
public class WebPart1 :
Microsoft.SharePoint.WebPartPages.WebPart
{
DataGrid MyDataGrid = new DataGrid();
protected override void
CreateChildControls (){
SqlConnection myConnection = new
SqlConnection("server=(local)
\\NetSDK;database=pubs;Integrated Security=SSPI");
myConnection.Open();
SqlDataAdapter myCommand = new
SqlDataAdapter("select au_id from Authors where au_lname
like '%Whi%'", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");
this.Controls.Add(MyDataGrid );
MyDataGrid.DataSource=ds.Tables
["Authors"].DefaultView;
MyDataGrid.DataBind();
myConnection.Close();
}
protected override void RenderWebPart
(HtmlTextWriter output)
{
EnsureChildControls();
output.RenderBeginTag
("table");
output.RenderBeginTag("tr"); //Add
a row
output.RenderBeginTag("td"); //
Add a cell
//Render DataGrid
MyDataGrid.RenderControl
(output);
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
}
}
}
Gracias.
Por favor si alguien sabe algo??
Leticia.
Pd: si este código lo meto en un aspx, funciona.
Leer las respuestas