/// <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);
}