因看不懂,请教一段程序?
protected void gv_Privilege_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = (DataRowView)e.Row.DataItem;
if (drv == null)
{
return;
}
for (int i = 0; i < drv.DataView.Table.Columns.Count; i++)
{
if (drv.DataView.Table.Columns[i].ColumnName != "资源名称")
{
//问题一?
CheckBox chk = (CheckBox)e.Row.Cells[i].Controls[0];
if (Convert.ToBoolean(drv[drv.DataView.Table.Columns[i].ColumnName].ToString()))
{
string roleId = lbl_GroupName.Attributes["RoleId"].ToString();
string privilegeId = new SMS_Privilege().GetPrivilegeId(drv[0].ToString(), drv.DataView.Table.Columns[i].ColumnName);
//问题二
drv[i] = SMS_PrivilegeInRoles.PrivilegeInRolesIsExists(new Guid(roleId), new Guid(privilegeId));
chk.Enabled = true;
}
else
{
chk.Visible = false; }
}
}
}
}
------------------------------------------------
问题一:CheckBox chk = (CheckBox)e.Row.Cells[i].Controls[0];
该语句是创建一个checkbox类型的chk呢,还是获得一个checkbox类型的chk
是不是cell可以转换成checkbox,还是cell中包含了controls是checkbox类类型的.
问题二:datarowview的drv[i]的赋值的作用?
drv[i]值是指什么?是列的名称吗?
为什么如果SMS_PrivilegeInRoles.PrivilegeInRolesIsExists(new Guid(roleId), new Guid(privilegeId));返回值是false的话.
则chk.Enabled = true;的执行效果无效,即chk.enabled属性超出if语句后又变成了false.