martes, 1 de septiembre de 2009

Ado.Net: Códigos valiosos.

ConfigurationManager
Dim cnn As New SqlConnection(ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString)
Response.Write(cnn.ConnectionString)

ConfigurationManager
System.Configuration.ConfigurationSettings.AppSettings["connstr"].ToString();

ConfigurationManager
ConfigurationManager.GetSection("prodSection")

ConfigurationManager
ConfigurationManager.GetWebAppSection("prodSection")

Agregar atributo a una fila de un GridView en Asp.Net:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='White'");
}
}

Insertar código JS:

Dim script As New StringBuilder
script.Append("")
Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "MyScript", script.ToString)

Filtrar items que se van insertando en un Repeater control de Asp.Net:


Protected Sub Repeater1_ItemCreated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemCreated
Dim nav As XPathNavigator = CType(e.Item.DataItem, IXPathNavigable).CreateNavigator

For Each o As Object In e.Item.Controls
If TypeOf o Is HtmlAnchor Then
Dim pagina As String = nav.Select("/Titulos/Titulo").Current.SelectSingleNode("pagina").Value
If pagina = "Cursos" Then
If User.Identity.IsAuthenticated Then
Dim archivo As String = nav.Select("/Titulos/Titulo").Current.SelectSingleNode("archivo").Value

o.Attributes.Add("href", "media/images/" + archivo)
o.Attributes.Add("rel", "lightbox[roadtrip]")

Else
o.Attributes.Add("href", "/")
o.Attributes.Add("class", "verModal")
End If
Else
e.Item.Visible = False
End If
End If
Next
End Sub

No hay comentarios: