Tuesday, August 18, 2009

Using JQuery to retrieve elements outside of IFrame

Let's say you have a AJAX-enabled Dialog box and you used IFrame to load a page (php / aspx) . Retrieving any element outside of this page requires asking JQuery to go out of its scope.

You can use the following code to retrieve element outside of your IFrame.

$("#myDiv", top.window)

Friday, August 14, 2009

ASP.net ListView

The following examples give an overview of how to use ListView.

Simple ListView


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="JL.aspx.cs" Inherits="JL" %>

<%@ Register Assembly="SystemCore.CommonAppControls" Namespace="SystemCore.CommonAppControls"
TagPrefix="cc1" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<asp:PlaceHolder runat="server" ID="test">Id :
<%# Eval("id") %>
<br />
</asp:PlaceHolder>
</ItemTemplate>
</asp:ListView>
</div>
</form>

<script runat="server">
protected override void OnLoad(EventArgs e)
{
ListView1.DataSource = Util.GetData();
ListView1.DataBind();
base.OnLoad(e);
}
</script>

</body>
</html>


Simple ListView With DataPager



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LVPager.aspx.cs" Inherits="LVPager" %>

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

<%@ Register Assembly="SystemCore.CommonAppControls" Namespace="SystemCore.CommonAppControls"
TagPrefix="cc1" %>
<!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 id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<asp:PlaceHolder runat="server" ID="test">Id :
<%# Eval("id") %>
<br />
</asp:PlaceHolder>
</ItemTemplate>
</asp:ListView>
<asp:DataPager runat="server" ID="lvPager" PagedControlID="ListView1" PageSize="3">
<Fields>
<asp:NumericPagerField Visible=true />
</Fields>
</asp:DataPager>
</div>
</form>

<script runat="server">
protected override void OnLoad(EventArgs e)
{
ListView1.DataSource = Util.GetData();
ListView1.DataBind();
base.OnLoad(e);
}
</script>

</body>
</html>


Control to Add DataBinding functionality into your ListView Templates

The key item to note here are adding databinding event and customizing your template namely, ItemTemplate.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Drawing;
using System.Web;

namespace SystemCore.CommonAppControls
{

[ToolboxData("<{0}:JList runat=server>")]
public class JList : Control
{

public ListView lv { get; set; }

public JList()
{
lv = new ListView();
}
protected override void OnInit(EventArgs e)
{
lv.LayoutTemplate = new LayoutTemplate();
lv.ItemTemplate = new ItemTemplate();
lv.EditItemTemplate = new EditItemTemplate();
base.OnInit(e);
}

protected override void CreateChildControls()
{
Controls.Add(lv);
base.CreateChildControls();
}

}

public class LayoutTemplate : Control, ITemplate
{
PlaceHolder pHolder = null;

public LayoutTemplate()
{
pHolder = new PlaceHolder();
}

protected override void OnInit(EventArgs e)
{

base.OnInit(e);
}

protected override void CreateChildControls()
{
base.CreateChildControls();
}

public void InstantiateIn(Control container)
{
pHolder.ID = "itemPlaceholder";
container.Controls.Add(pHolder);
}
}


public class ItemTemplate : Control, ITemplate
{
protected override void CreateChildControls()
{
base.CreateChildControls();
}

public void InstantiateIn(Control container)
{
PlaceHolder p = new PlaceHolder() { ID = "test2" };

Label txtName = new Label();
txtName.Text = "Username:";
txtName.DataBinding += new EventHandler(txtName_DataBinding);

Label Passwrd = new Label();
Passwrd.Text = "Password";
Passwrd.DataBinding += new EventHandler(Passwrd_DataBinding);

p.Controls.Add(txtName);
p.Controls.Add(Passwrd);
container.Controls.Add(p);
}

void txtName_DataBinding(object sender, EventArgs e)
{
}

void Passwrd_DataBinding(object sender, EventArgs e)
{

IDataItemContainer d = (IDataItemContainer)((Label)sender).NamingContainer;
var x = (string)DataBinder.Eval(d.DataItem, "id").ToString();

((Label)sender).Text = (String)DataBinder.Eval(((IDataItemContainer)((Label)sender).NamingContainer).DataItem, "id").ToString();
}
}

public class EditItemTemplate : Control, ITemplate
{
protected override void CreateChildControls()
{
this.Controls.Add(new PlaceHolder() { ID = "test" });
TextBox txtName = new TextBox();
txtName.Text = "Username";
TextBox Passwrd = new TextBox();
Passwrd.Text = "Password";
this.Controls.Add(new Label() { Text = "Name" });
Controls.Add(txtName);
this.Controls.Add(new Label() { Text = "Password" });
Controls.Add(Passwrd);

base.CreateChildControls();
}

#region ITemplate Members

public void InstantiateIn(Control container)
{
// throw new NotImplementedException();
}

#endregion
}

}




Friday, August 07, 2009

SSIS package throwing "the type initializer for 'System.Data.SqlClient.SqlConnection'

SSIS package throwing "the type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception"

I'm running SSIS package which references an assembly which calls a WCF web service. Everytime i run it, i get this weird
"the type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception".

So i decided to check on app.config setting in the following files located in C:\Program Files\Microsoft SQL Server\90\DTS\Binn folder.

a) DTExec.exe.config

b) DtsDebugHost.exe.config

c) dtshost.exe.config

It has nothing to do with these configurations.

Solution

Try installing Microsoft .Net Framework 3.0 (in my case) and it solve my issue.