Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Select items from Datagrid header and display in rows [Javascript] [Chatakondu Gallery]

Reply
Thread Tools

Select items from Datagrid header and display in rows [Javascript] [Chatakondu Gallery]

 
 
Suresh
Guest
Posts: n/a
 
      04-16-2004
formName: name of the form
ctrlCheckBox: left side check boxes
ctrlSrcField: source fields where the value is coming from
ctrlHidSrcField: hidden source field. in case if you need to pass
hidden values from source field.
ctrlDestField: destination field where the value will be displayed.
ctrlHidDestField: hidden destination field. in case if you need to
pass hidden value back.
ErrMessageText: error text message if you need to display when error
occurred.

[Here is the example how this can be used.
1) Create a data grid.
2) First column in header is check box and items also checkboxes
{ctrlCheckBox - field}.
3-a) Second column in header is Drop-down box {ctrlSrcField} . And
you have drop-down boxes {ctrlDestField} in items also. And you have
'GO' button also in header.
(or)
3-b)Second column in header is Text Box {ctrlSrcField,
ctrlHidSrcField}. And you have text-boxes {ctrlDestField,
ctrlHidDestField} in items also. And you have 'GO' button also in
header.

4) Select a value from header control and select number of check
boxes from items and click 'GO' button. Selected value will be
displayed in destination controls.

5) This is very useful when you want update multiple rows data from
header.
]


function fnFillItem(formName, ctrlCheckBox, ctrlSrcField,
ctrlHidSrcField, ctrlDestField, ctrlHidDestField, ErrMessageText)
{
if (formName == '')
var formName = document.forms(0).name
obj = eval("document." + formName)

var objctrlSrcField, objctrlHidSrcField;

for (var i=0;i<obj.elements.length;i++)
{
var e = obj.elements[i];
var elementName = e.name.toString()
if (elementName.indexOf(ctrlSrcField) >= 0 )
{
objctrlSrcField = e;
}
if (ctrlHidSrcField != '')
if (elementName.indexOf(ctrlHidSrcField) >= 0 )
{
objctrlHidSrcField = e;
}
}
//check at least one check box is checked
var AtLeastOneChecked = false;
for (var i=0;i<obj.elements.length;i++)
{
var e = obj.elements[i];
var elementName = e.name.toString()
if (elementName.indexOf(ctrlCheckBox) >= 0 )
if (e.checked )
{
AtLeastOneChecked = true;
break;
}
}
if (!AtLeastOneChecked)
{
alert("Please check at least one checkbox");
return;
}
// Assign values to dest fields
for (var i=0;i<obj.elements.length;i++)
{
var e = obj.elements[i];
var elementName = e.name.toString()

if (elementName.indexOf(ctrlCheckBox) >= 0 )
if (e.checked)
{
var objctrlDestField = eval("document.forms[" + "\"" + formName +
"\"" + "].item(" + "\"" + elementName.substring(0,
elementName.indexOf(ctrlCheckBox)) + ctrlDestField + "\")")

if (objctrlSrcField.type == 'select-one') //if the source
control is drop-down or list box
{
// If it is drop-down and not selected pop-up error message
//if (objctrlSrcField.value == '')
//{
// alert(ErrMessageText)
// objctrlSrcField.focus();
// return;
//}

// if the destination control is drop-down or list box
if (objctrlDestField.type == 'select-one' ||
objctrlDestField.type == 'select-multiple' )
{
var ItemExistInDestField = false;

// check if item is already in the list box
for (var j = 0; j < objctrlDestField.options.length; j++)
if (objctrlSrcField.value == objctrlDestField.options[j].value)
{
ItemExistInDestField = true;
break;
}

if (!ItemExistInDestField && objctrlSrcField.value != '')
{
var NewOption = document.createElement("OPTION");
NewOption.value = objctrlSrcField.value;
NewOption.text =
objctrlSrcField.options[objctrlSrcField.selectedIndex].text;
objctrlDestField.add(NewOption);
objctrlDestField.options(objctrlDestField.length-1).selected =
true;
}
}
else
{
//if the destination control is other than drop-down or list box
if (objctrlSrcField.value == '')
objctrlDestField.value = ""
else
objctrlDestField.value =
objctrlSrcField.options[objctrlSrcField.selectedIndex].text
}
} //if (objctrlSrcField.type == 'select-one')

else if (objctrlSrcField.type == 'text') //if the source
control is text box
{
// if the destination control is drop-down or list box
if (objctrlDestField.type == 'select-one')
{
var ItemExistInDestField = false;

// check if item is already in the list box
for (var k = 0; k < objctrlDestField.options.length; k++)
if (objctrlHidSrcField.value ==
objctrlDestField.options[k].value)
{
ItemExistInDestField = true;
break;
}

if (!ItemExistInDestField && objctrlSrcField.value != '')
{
var NewOption = document.createElement("OPTION");
NewOption.value = objctrlHidSrcField.value;
NewOption.text = objctrlSrcField.value;
objctrlDestField.add(NewOption);
objctrlDestField.options(objctrlDestField.length-1).selected =
true;

}
}
else //if the destination control is other than
drop-down or list box
objctrlDestField.value = objctrlSrcField.value
}

else if (objctrlSrcField.type == 'checkbox') //if the source
control is check box
objctrlDestField.checked = objctrlSrcField.checked

//if (ctrlHidDestField != '')
//{
// var objctrlHidDestField = eval("document.forms[" + "\"" +
formName + "\"" + "].item(" + "\"" + elementName.substring(0,
elementName.indexOf(ctrlCheckBox)) + ctrlHidDestField + "\")")
// objctrlHidDestField.value = objctrlSrcField.value
//}
}
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hide the Gridview Rows and Header rows in Button click VijayRama ASP .Net 2 10-12-2009 01:58 PM
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
Itemdatabound event fires once for Datagrid header only and NOT for data rows bkasmai@gmail.com ASP .Net Datagrid Control 0 07-23-2006 09:40 AM
Any way to reorder how a datagrid is drawn (header/footer/items vs.header/items/footer)? Henrik ASP .Net Datagrid Control 1 07-06-2006 12:23 AM
How can I select items in a datagrid to populate a second datagrid. Eric ASP .Net Datagrid Control 5 08-04-2004 12:43 AM



Advertisments