May 22, 2013

Detecting checked radio button on UI dialog

Here is container for jquery UI dialog filled with radio buttons:


<div id="gfdialog" title="Meldung vom Website">
            <div>xxxxxxxxxxxxxxxxxx?</div>
            <input type="radio" name="radLstCopyType" value="1" checked="checked" /><span>Option 1</span>
            <div style="margin-left: 21px!important; margin-bottom: 15px;">Option 2.</div>
            <input type="radio" name="radLstCopyType" value="3" />
            <span>Szenario-CFG</span>
            <div style="margin-left: 21px!important; margin-bottom: 15px;">Option 3</div>
            <input type="radio" name="radLstCopyType" value="2" />
            <span>Muster-CFG</span>
            <div style="margin-left: 21px!important; margin-bottom: 15px;">xxxxxxxxxxxxxxxxxx.</div>
        </div>

; and here is code that gets checked radio button:


function RegisterGFCopyBGDialog() {          
            $("#gfdialog").dialog({
               
                autoOpen: false,
                width: 400,
                buttons: [
                    {
                        text: "Ok",
                        click: function () {
                            var selectedCFG_artId = $('input[name="radLstCopyType"]:checked').val();                          
                           
                            if (selectedCFG_artId == null) return;
                            __doPostBack('radLstCopyType', selectedCFG_artId);
                            $(this).dialog("close");
                        }
                    },
                    {
                        text: "Abbrechen",
                        click: function () {
                            $(this).dialog("close");
                        }
                    }
                ]
            });
        }


Most important part is  :

$('input[name="radLstCopyType"]:checked').val();                           

and NOT:

$('input[name="radLstCopyType"][checked="checked"']).val();                          

or

$('input[name="radLstCopyType"][checked="true"']).val();                          

or

$('input[name="radLstCopyType"][checked]).val();                          


May 3, 2013

Linq lambda group by aggregate by multiple columns



Example of grouping input DataTable by string column and getting aggregate MAX for second bool column:
     var sTables = (bindSrcColumns.DataSource as DataTable).Rows.Cast<DataRow>())
                        .GroupBy(r =>   ColumnsHelper.GetTablePart(r[EDITORCOLUMN_FIELDNAME].ToString()))
                        .Select(g => new Tuple<string, bool>(g.Key, g.Max(m => m[EDITORCOLUMN_ISSELECTED] as bool? ?? false)))
                        .OrderBy(s=>s.Item1)
                        .ToList();