Checkbox is always false in IE using javascript function - asp.net

I have a function in javascript which checks the state of checkboxes (used as labels) and sends a list of checked boxes to printing command in vb.net code.
I am calling this javascript function from ImageClick code.
Problem is state of the check boxes is lost in IE and is always False but in chrome it considers the right state.
<asp:ImageButton ID="PrintCustName" ImageUrl="images/print.jpg" runat="server" OnClientClick = "return myFunction();" />
function in JS and
Declaration of chkb is as follows;:
function myFunction() {
var c1 = document.getElementById('c1'),
c2 = document.getElementById('c2'), // Checkbox 2
c3 = document.getElementById('c3'), // Checkbox 3
c4 = document.getElementById('c4'), // Checkbox 4
c5 = document.getElementById('c5'), // Checkbox 5
c6 = document.getElementById('c6'), // Checkbox 6
c7 = document.getElementById('c7'), // Checkbox 7
c8 = document.getElementById('c8'), // Checkbox 8
c9 = document.getElementById('c9'), // Checkbox 9
c10 = document.getElementById('c10'), // Checkbox 10
c11 = document.getElementById('c11'), // Checkbox 11
c12 = document.getElementById('c12'), // Checkbox 12
c13 = document.getElementById('c13'), // Checkbox 13
c14 = document.getElementById('c14'), // Checkbox 14
c15 = document.getElementById('c15'), // Checkbox 15
var LblNumber = new Array();
if (c1.checked) LblNumber[0] = c1.value; else LblNumber[0] = 0;
if (c2.checked) LblNumber[1] = c2.value; else LblNumber[1] = 0;
if (c3.checked) LblNumber[2] = c3.value; else LblNumber[2] = 0;
if (c4.checked) LblNumber[3] = c4.value; else LblNumber[3] = 0;
if (c5.checked) LblNumber[4] = c5.value; else LblNumber[4] = 0;
if (c6.checked) LblNumber[5] = c6.value; else LblNumber[5] = 0;
if (c7.checked) LblNumber[6] = c7.value; else LblNumber[6] = 0;
if (c8.checked) LblNumber[7] = c8.value; else LblNumber[7] = 0;
if (c9.checked) LblNumber[8] = c9.value; else LblNumber[8] = 0;
if (c10.checked) LblNumber[9] = c10.value; else LblNumber[9] = 0;
if (c11.checked) LblNumber[10] = c11.value; else LblNumber[10] = 0;
if (c12.checked) LblNumber[11] = c12.value; else LblNumber[11] = 0;
if (c13.checked) LblNumber[12] = c13.value; else LblNumber[12] = 0;
if (c14.checked) LblNumber[13] = c14.value; else LblNumber[13] = 0;
if (c15.checked) LblNumber[14] = c15.value; else LblNumber[14] = 0;
alert("printing on label " + LblNumber);
document.getElementById("<%= HidLblNumber.ClientID%>").value = LblNumber;
<fieldset class = "group">
legend>Select Used Labels:</legend>
label >input type="checkbox" id = "c1" name= "Lbl" value = "1"/>img src="images/Action-ok-icon32.png" onclick="clickFunction(this)"/> /label>
I have tried looking different posts but nothing helped. why is IE not retaining the state of checkbox after print button is clicked is my question?
help!

Related

Repeater binding with for loop to retrieve multiple values from database

This my code i want to fetch values fron database and insert in the repeater this code only returns last value from database
for (int i = 0; i < dtFinalVessel.Rows.Count; i++)
if (i == 0)
{
if (e.Item.ItemType == ListItemType.Item)
{
DataTable dtCostElement = DAL.MonthlyCrudeAccrualsDetail.GetMonthlyCrudeAccrualsPerFinalBolID_Get_List(int.Parse(dtFinalVessel.Rows[0]["FinalVesselPerBOLID"].ToString()));
ArrayList arrlist = new ArrayList();
Repeater rptrCostElementHeader = (Repeater)e.Item.FindControl("rptrCostElementHeader");
rptrCostElementHeader.DataSource = dtCostElement;
rptrCostElementHeader.DataBind();
Repeater rptrUS = (Repeater)e.Item.FindControl("rptrUS");
rptrUS.DataSource = dtCostElement;
rptrUS.DataBind();
Repeater rptrZAR = (Repeater)e.Item.FindControl("rptrZAR");
rptrZAR.DataSource = dtCostElement;
rptrZAR.DataBind();
Repeater rptrUSCent = (Repeater)e.Item.FindControl("rptrUSCent");
rptrUSCent.DataSource = dtCostElement;
rptrUSCent.DataBind();
for (int j = 0; j < dtCostElement.Rows.Count; j++)
{
string strUscent = dtCostElement.Rows[j]["USCent"].ToString();
decimal total = decimal.Parse(strUscent.ToString()) / decimal.Parse(hdnTotalVessel.Value.ToString());
arrlist.Add(total.ToString());
}
Repeater rptAvgUSCent = (Repeater)e.Item.FindControl("rptAvgUSCent");
rptAvgUSCent.DataSource = arrlist;
rptAvgUSCent.DataBind();`
}
}
}

How to specify checkbox data for saving to a bit field

If a checkbox produces TRUE or FALSE, how do I convert to 1 or 0 to save the value to the database?
ASP.NET
<asp:CheckBox ID="cbTermsandcond" runat="server" />
C#
BTermsandcondParam = new SqlParameter();
BTermsandcondParam.ParameterName = "#BTermsandcondParam";
BTermsandcondParam.SqlDbType = SqlDbType.Bit;
BTermsandcondParam.Direction = ParameterDirection.Input;
BTermsandcondParam.Value = cbTermsandcond. ??? ;
EDIT:
I wrote this which worked. But is there a simplier way?
if (cbTermsandcond.Checked == true)
{
BTermsandcondParam.Value = 1;
}
else
{
BTermsandcondParam.Value = 0;
}
Regards
Tea
BTermsandcondParam.Value = cbTermsandcond.Checked

Extjs4 multigrouping header value css

I am using the Extjs4 multigrouping plugin from here.
I have used it successfully, however i want to show the summary of the totals of each column within the group header itself . how do i set up the appropriate CSS for that ?
In Multigrouping.js
getFragmentTpl: function() {
var me = this;
return {
indentByDepth: me.indentByDepth,
depthToIndent: me.depthToIndent,
renderGroupHeaderTpl: function(values, parent) {
return Ext.XTemplate.getTpl(me, 'groupHeaderTpl').apply(values, parent);
//var z = new Ext.XTemplate('{name} ({rows.grouplength})');
//return z.apply(values, parent);
}
};
},
In my grid
features: [
{
ftype:'multigrouping',
groupHeaderTpl: [
'{[this.readOut(values)]}',
{
readOut:function(values) {
debugger;
var sum1 =0 ,sum2=0,sum3=0;
for( var i = 0 ; i< values.records.length ; i++)
{
var val = parseFloat(values.records[i].data.d2012.mp);
sum1 += isNaN(val) ? 0.0 : val;
val = parseFloat(values.records[i].data.d2013.mp);
sum2 += isNaN(val) ? 0.0 : val;
val = parseFloat(values.records[i].data.d2014.mp);
sum3 += isNaN(val) ? 0.0 : val;
}
return values.name + '(' + values.records.length + ')' + ' ' + sum1.toFixed(2) + ' ' + sum2.toFixed(2) + ' ' + sum3.toFixed(2);
}
}
]
},
had to resort to a few hacks to get this to work. still waiting on an official answer.
The main reason i had to do this and not use the multigrouping summary is because
- i want to limit the number of records from the server. I can do some smart grouping of
my business objects at the server side.
- the main reason to do this is because of IE8's performance on larger sets of data.
- had already tried the extjs4 tree grid component which works well on chrome but had performance issues on IE8.
the hack is to
a) use an array property in the grid to store the dom elements which i want to manipulate
b) use a boolean to know when the layout is completed the first time
b) add listeners for afterlayout ( when your app can do an Ext.get('..dom element..') you know you are done )
The listener :
listeners :
{
afterlayout : function(eopts)
{
var x = this.mOwnArray;
if(!this.loadedwithVals && x.length > 0)
{
for(var i =0 ; i<x.length ; i++)
{
var dom = Ext.get(x[i].id);
var theId = dom.id;
theId = theId.match(/\d+/)[0];
var title = dom.query("td[class='x-grid-cell x-grid-cell-first']");
title[0].className = 'x-grid-cell x-grid-cell-gridcolumn-' + theId + ' x-grid-cell-first';
title[0].colSpan=1;
var groupedHeader = dom.query("div[class='x-grid-group-title']");
groupedHeader[0].innerHTML = x[i].name + '(' + x[i].length + ')';
for(var year=2012;year<=2018;year++)
{
var t = "t"+year;
var someText1 = '<td class=" x-grid-cell x-grid-cell-numbercolumn">';
var someText2 = '<div class="x-grid-cell-inner " style="text-align: left; ;">';
var someText3 = '<div class="x-grid-group-title">' + x[i].total[t] + '</div></div></td>';
var someText = someText1 + someText2 + someText3;
dom.insertHtml("beforeEnd",someText);
}
}
this.loadedwithVals = true;
}
}
And the feature as in
features: [
{
ftype:'multigrouping',
startCollapsed : true,
groupHeaderTpl: [
'{[this.readOut(values)]}',
{
readOut:function(values) {
var header = new Object();
header.id = values.groupHeaderId;
header.sum = [];
header.total = new Object();
for(var year = 2012 ; year <= 2018 ; year++)
{
var t = "t"+year;
header.total[t] = [];
}
// all the records in this header
for( var i = 0 ; i< values.records.length ; i++)
{
// for all the 'years' in this record
for(var year=2012;year<=2018;year++)
{
var d = "d"+year;
var ct = "t" + year;
var arecord = values.records[i].data;
var val = parseFloat(arecord[d].mp);
val = isNaN(val) ? 0.0 : val;
Ext.Array.push(header.total[ct],val);
}
}
// push the sum of the records into its top level group
for(var year = 2012 ; year <= 2018 ; year++)
{
var t = "t"+year;
var sum = Ext.Array.sum(header.total[t]);
header.total[t] = sum.toFixed(2);
}
header.name = values.name;
header.length = values.records.length;
var headerName = values.name;
if(values.hasOwnProperty('parent'))
{
var parent = values.parent;
headerName = headerName.replace(parent,'');
}
header.name = headerName;
header.length = values.records.length;
Ext.Array.push(grid.mOwnArray,header);
// really not used
return values.name + '(' + values.records.length + ')';
}
}
]
},
]

shift select records in gridview asp.net

hey guys,
i have a gridview which displays 10records per page, now i want to implement shift+click option in my gridview, when user clicks on the first row and press shift key and click on the 5th row, all the rows between 1 and 5(1 and 5 inclusive) should be selected...
can anyone suggest how should i do this in javascript.
I take it back, I found a shift+click multiple select solution for a gridview. All credit goes to mdv over at the asp forums.
var _sPreviousRow = null;
function wsCheckRange(p_oGridView, p_oControl, e) {
var l_sCheckID = p_oControl.id;
var l_aCheckIDParts = l_sCheckID.split(p_oGridView.id);
var l_sCurrentRow = l_aCheckIDParts[1].split('_')[1].substring(3);
var l_oEvent = (window.event) ? event : e;
if (l_oEvent.shiftKey) {
if (_sPreviousRow != null && _sPreviousRow != l_sCurrentRow) {
var l_iFirst = 0, l_iLast = 0;
if (parseInt(_sPreviousRow,10) > parseInt(l_sCurrentRow,10)) {
l_iFirst = parseInt(l_sCurrentRow,10);
l_iLast = parseInt(_sPreviousRow,10);
}
else {
l_iFirst = parseInt(_sPreviousRow,10);
l_iLast = parseInt(l_sCurrentRow,10);
}
for (var i = l_iFirst; i < l_iLast; i++) {
var l_sLastRow = (i <= 9 ? '0' + i : i);
var l_sCtrlNew = l_sCheckID.replace('ctl' + l_sCurrentRow, 'ctl' + l_sLastRow);
var l_oCtrlNew = $get(l_sCtrlNew);
if (l_oCtrlNew) {
l_oCtrlNew.checked = p_oControl.checked;
}
}
}
_sPreviousRow = null;
}
else {
_sPreviousRow = l_sCurrentRow;
}
}

Flex AdvancedDataGrid Custom Sorting problem

I have an advanced datagrid and I am implementing a custom sort. My adv.data grid slows down on each consequent sorting...and if the nodes are opened, it simply times out.
My data looks like the following (g = grp on ID)*
ID f_name l_name fld1 fld2
(g)
--------------------------------------
1 A1 B1 xyx xyz
A6 B6 xyx xyz
--------------------------------------
2 A3 B3 xyx xyz
A8 B8 xyx xyz
--------------------------------------
When I sort on F_NAME or L_NAME the sorting ArrayCollection should sort and show data as follows(g = grp on ID)*:
ID f_name l_name fld1 fld2
(g)
-----------------------------------------
1(1) A1 B1 xyx xyz
2(2) A3 B3 xyx xyz
-----------------------------------------
1(3) A6 B6 xyx xyz
2(4) A6 B6 xyx xyz
-----------------------------------------
To do this I am employing a sort event which looks like the following
protected function adg1_headerReleaseHandler(event:AdvancedDataGridEvent):void
{
event.preventDefault();
sort_dir = !sort_dir;
var sort:Sort = new Sort();
sort.fields = [new SortField(event.dataField, true,sort_dir),new SortField('ID', true,sort_dir)]
_ds.sort = sort;
_ds.refresh();
adg1.dataProvider = null;
var previousRegId:int = 0;
var counter:int = 0;
for each (var item:DueInVO in _ds) {
if (previousRegId != item.ID) {
counter++;
previousRegId = item.ID
}
item.uid = counter;
}
/*
var previousRegId:int = 0;
var counter:int = 0;
var csr:IViewCursor = DataSource.createCursor();
while(!csr.afterLast){
if (previousRegId != csr.current.registration_id) {
counter++;
previousRegId = csr.current.registration_id
}
csr.current.uid = counter;
csr.moveNext();
}
*/
setGrouping(['uid']);
//csr = null;
}
and the setGrouping function looks like the following:
protected function setGrouping(columnNames:Array):void{
var _groupingColumns:Array = [];
var gc:GroupingField;
if (columnNames.length > 0) {
var _groupedData:GroupingCollection2 = new GroupingCollection2();
var _grouping:Grouping = new Grouping();
for (var i:int=0;i<columnNames.length;i++) {
gc = new GroupingField(columnNames[i]);
//gc.numeric = true;
//gc.compareFunction = compareFunc;
//gc.groupingFunction = groupFunc;
_groupingColumns.push(gc);
}
_groupedData.source = _ds;
_grouping.fields = _groupingColumns;
_groupedData.grouping = _grouping
_groupedData.refresh();
adg1.dataProvider = _groupedData;
} else {
adg1.dataProvider = _ds;
}
}
However each consequent request to sort is taking longer and longer to resolve. As stated above, if the nodes of grouping are opned, then there is a high likelyhood that Flash player crashes.
I am guessing there is a mem-leak somewhere but I am not able to put a finger on it.
If anyone requires the full code, I will be happy to provide it..
All help is greatly appreciated
Instead of doing this, you should simply provide a sortCompareFunction to your ADG column. You don't have to capture the header click event and all that. It's already done for you. All you have to do is specify how your comparison for a particular column will play out.
I got it!... Robusto thanks for pointing me in somewhat right direction. The problem with your suggestion in my case is that I am generating columns from a config file, so I can make this grid-component reusable. So because of that:
1. I am using a labelFunction
2. column.sortCompareFunction = myfunc callback simply doesn't work as quoted from Adobe API documentation.
However, as you said, I was writing convoluted code. I needed to add gc.compareFunction = myCompare; to the following code (compare from above):
protected function setGrouping(columnNames:Array):void{
_groupingColumns = [];
if (columnNames.length > 0) {
_groupedData = new GroupingCollection2();
_grouping = new Grouping();
for (var i:int=0;i<columnNames.length;i++) {
var gc:GroupingField = new GroupingField(columnNames[i]);
gc.descending = _sort_direction;
gc.compareFunction = myCompare;
_groupingColumns.push(gc);
}
_groupedData.source = _ds;
_grouping.fields = _groupingColumns;
_groupedData.grouping = _grouping
_groupedData.refresh();
_data = _groupedData;
} else {
_data = _ds;
}
setGridColumns();
}
Once that was done I just had to listen to the sort event in the AdvancedDataGrid listener and call the setGrouping([abc]) from there, as follows:
protected function adg1_sortHandler(event:AdvancedDataGridEvent):void
{
_sortField = event.dataField;
if (temp.length == 0) {
temp.push(DefaultGroupColumn);
}
setGrouping(temp)
_sort_direction = !_sort_direction;
I hope this helps someone!
AAP

Resources