Monday, November 16, 2009

GridView: get selected rows

Below is sample C# code to get selected rows in GridView.

protected int[] GetSelectedRows()
{
List rowIDs = new List();
foreach (GridViewRow row in GridView.Rows)
{
CheckBox cb = ((CheckBox)row.FindControl("chkRow"));
if (cb.Checked)
{
string IDString = GridView.DataKeys[row.RowIndex].Value.ToString();
rowIDs.Add(Int32.Parse(IDString));
}
}
return rowIDs.ToArray();
}

"SelectAll" CheckBox in GridView using jQuery

Here is a way to do it:


/**
* Register logic for "select all" check box and the group of check boxes
* for each data row.
*
* @param {Object} chkAllSelector jQuery selector to find the "select all" check box
* @param {Object} chkItemSelector jQuery selector to find the check boxes for all the rows
*/

function registerSelectAll(chkAllSelector, chkItemSelector) {
//"select all" checkbox
var checkAllBox = $(chkAllSelector);
//checkbox for each row
var checkItems = $(chkItemSelector);

//check/uncheck all rows if "select all" is clicked
checkAllBox.bind("click", function(){
checkItems.each(function(){
this.checked = checkAllBox[0].checked;
})
});

//uncheck "select all" if some rows are unchecked
checkItems.bind("click", function(){
if(this.checked === false) {
checkAllBox[0].checked = false;
}
});
}


To use it:

registerSelectAll(".chkAllHeader input", ".chkItem input");

Monday, November 09, 2009

"An unexpected error occurred." accessing Network Connection's properties

Cause: seems like it suddenly happens after a recent Windows Update. I cannot ping or "remote desktop" to the computer. Trying to access network connection give me this error: "An unexpected error occurred."

Solution:
This seems to fix the problem:
command line:
regsvr32 netshell.dll
regsvr32 ole32.dll
reboot

Then I can access the properties page, and I disable/re-enabled firewall. Everything coming back to normal.

P.S.
Keep my fingers crossed. Waiting for more surprised from next automatic Windows Update.