/// <summary>
/// OnRowDataBound
/// </summary>
/// <param name="e"></param>
protected
override
void OnRowDataBound(GridViewRowEventArgs e)

{
if (e.Row.RowType == DataControlRowType.DataRow)

{
// GridViewRow的每一个TableCell
for (
int i = 0; i < e.Row.Cells.Count; i++)

{
// TableCell里的每一个Control
for (
int j = 0; j < e.Row.Cells[i].Controls.Count; j++)

{
if (e.Row.Cells[i].Controls[j]
is CheckBox)

{

CheckBox chk = (CheckBox)e.Row.Cells[i].Controls[j];
// 判断该CheckBox是否属于全选CheckBox
bool isCheckboxAll =
false;
foreach (CheckboxAll ca
in CheckboxAlls)

{
if (chk.NamingContainer.ClientID +
"_" + ca.CheckboxItemID == chk.ClientID)

{

isCheckboxAll =
true;
break;

}

}
// 给该CheckBox增长客户端代码
if (isCheckboxAll)

{
// 给Control增长一个客户端onclick

chk.Attributes.Add(
"onclick",
"yy_ClickCheckItem()");
// 给_checkItemIDDictionary赋值
if (_checkItemIDDictionary.Count == 0 || !_checkItemIDDictionary.ContainsKey(i))

{

_checkItemIDDictionary.Add(i, chk.ClientID);

}
else

{
string s;

_checkItemIDDictionary.TryGetValue(i,
out s);

_checkItemIDDictionary.Remove(i);

_checkItemIDDictionary.Add(i, s +
this.ItemSeparator + chk.ClientID);

}
break;

}

}

}

}

}
else
if (e.Row.RowType == DataControlRowType.Header)

{
// GridViewRow的每一个TableCell
for (
int i = 0; i < e.Row.Cells.Count; i++)

{
// TableCell里的每一个Control
for (
int j = 0; j < e.Row.Cells[i].Controls.Count; j++)

{
if (e.Row.Cells[i].Controls[j]
is CheckBox)

{

CheckBox chk = (CheckBox)e.Row.Cells[i].Controls[j];
// 判断该CheckBox是否属于全选CheckBox
bool isCheckboxAll =
false;
foreach (CheckboxAll ca
in CheckboxAlls)

{
if (chk.NamingContainer.ClientID +
"_" + ca.CheckboxAllID == chk.ClientID)

{

isCheckboxAll =
true;
break;

}

}
// 给该CheckBox增长客户端代码
if (isCheckboxAll)

{
// 给Control增长一个客户端onclick

chk.Attributes.Add(
"onclick",
"yy_ClickCheckAll(this)");
// 给_checkAllIDString赋值
if (String.IsNullOrEmpty(
this._checkAllIDString))

{
this._checkAllIDString += chk.ClientID;

}
else

{
this._checkAllIDString +=
this.GroupSeparator + chk.ClientID;

}
break;

}

}

}

}

}
base.OnRowDataBound(e);

}