Friday, September 5, 2008

importng xml file and displaying in table using javascript

//html



// JScript File
var xmlDoc;

function importXML()
{
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = createTable;
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4) createTable()
};
}
else
{
alert('Your browser can\'t handle this script');
return;
}
xmlDoc.load("http:path.xml")

}

function createTable()
{
debugger;
var x = xmlDoc.getElementsByTagName('item');

var tmp = document.createElement('TBODY');

for (j=0;j {
var row = document.createElement('TR');
tmp.appendChild(row);

var vtitles = x[j].getElementsByTagName("title");
var vlinks = x[j].getElementsByTagName("link");
var vdesc = x[j].getElementsByTagName("description");
var tdTitle = document.createElement('TD');
row.appendChild(tdTitle);

var tddesc = document.createElement('TD');
row.appendChild(tddesc);
var valink = document.createElement('A');
tdTitle.appendChild(valink);
valink.title = vtitles[0].text;
valink.href = vlinks[0].text;
valink.innerText = vtitles[0].text;

tddesc.innerText = vdesc[0].text;
}
document.getElementById('title').appendChild(tmp);


}

sending onelistbox items to another listbox using c#.net

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lstDisplay.Items.Add("satya");
lstDisplay.Items.Add("rama");
lstDisplay.Items.Add("jaga");
lstDisplay.Items.Add("mohan");
lstDisplay.Items.Add("sasi");
}
}


protected void btnFOne_Click(object sender, EventArgs e)
{
ListItemCollection licCollection;
try
{
licCollection = new ListItemCollection();
for (int intCount = 0; intCount < lstDisplay.Items.Count; intCount++)
{
if (lstDisplay.Items[intCount].Selected == true)
licCollection.Add(lstDisplay.Items[intCount]);
}
for (int intCount = 0; intCount < licCollection.Count; intCount++)
{
lstDisplay.Items.Remove(licCollection[intCount]);
lstAdd.Items.Add(licCollection[intCount]);
}
}
catch (Exception expException)
{
Response.Write(expException.Message);
}
finally
{
licCollection = null;
}
}

protected void btnBOne_Click(object sender, EventArgs e)
{
ListItemCollection licCollection;
try
{
licCollection = new ListItemCollection();
for (int intCount = 0; intCount < lstAdd.Items.Count; intCount++)
{
if (lstAdd.Items[intCount].Selected == true)
licCollection.Add(lstAdd.Items[intCount]);
}
for (int intCount = 0; intCount < licCollection.Count; intCount++)
{
lstAdd.Items.Remove(licCollection[intCount]);
lstDisplay.Items.Add(licCollection[intCount]);
}
}
catch (Exception expException)
{
Response.Write(expException.Message);
}
finally
{
licCollection = null;
}
}
protected void btnBmultiple_Click(object sender, EventArgs e)
{
try
{
foreach (ListItem item in lstAdd.Items)
lstDisplay.Items.Add(item);
lstAdd.Items.Clear();
}
catch (Exception expException)
{
Response.Write(expException.Message);
}
}
protected void btnfmultiple_click(object sender, EventArgs e)
{
try
{
foreach (ListItem item in lstDisplay.Items)
lstAdd.Items.Add(item);
lstDisplay.Items.Clear();
}
catch (Exception expException)
{
Response.Write(expException.Message);
}
}

creating listbox items and sending to another listbox using javascript

//Html Code










































//javascript code


// JScript File
function fnMoveItems(lstbxFrom,lstbxTo)
{
debugger;
var varFromBox = document.all(lstbxFrom);
var varToBox = document.all(lstbxTo);
if ((varFromBox != null) && (varToBox != null))
{
if(varFromBox.length < selectedindex ="="">= 0)
{
var newOption = new Option(); // Create a new instance of ListItem
newOption.text = varFromBox.options[varFromBox.options.selectedIndex].text;
newOption.value = varFromBox.options[varFromBox.options.selectedIndex].value;
varToBox.options[varToBox.length] = newOption; //Append the item in Target Listbox
varFromBox.remove(varFromBox.options.selectedIndex); //Remove the item from Source Listbox
}
setSize(varFromBox,varToBox);
}
return false;
}
function fnMoveMultItems(lstbxFrom,lstbxTo)
{
debugger;
var varFromBox = document.all(lstbxFrom);
var varToBox = document.all(lstbxTo);
var len = varFromBox.length -1;
if ((varFromBox != null) && (varToBox != null))
{
if(varFromBox.length < 1)
{
alert('There are no items in the source ListBox');
return false;
}

for(i=0; i<=len;i++){
var j=0;
varToBox.appendChild(varFromBox.item(j));
}
selectNone(varFromBox,varToBox);
setSize(varFromBox,varToBox);

}
return false;
}
function selectNone(list1,list2){
list1.selectedIndex = -1;
list2.selectedIndex = -1;
addIndex = -1;
selIndex = -1;
}
function getSize(list){
var len = list.childNodes.length;
var nsLen = 0;
//nodeType returns 1 for elements
for(i=0; i if(list.childNodes.item(i).nodeType==1)
nsLen++;
}
if(nsLen<2)
return 2;
else
return nsLen;
}
function setSize(list1,list2){
list1.size = getSize(list1);
list2.size = getSize(list2);
}