读书人

因看不懂,请问一段程序

发布时间: 2012-02-05 12:07:14 作者: rapoo

因看不懂,请教一段程序?
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.


[解决办法]
问题一:CheckBox chk = (CheckBox)e.Row.Cells[i].Controls[0];

该语句是获得一个checkbox类型的chk,是cell中包含了CheckBox类型的一个对象
[解决办法]
drv[i],i是列的索引值
[解决办法]
CheckBox chk = (CheckBox)e.Row.Cells[i].Controls[0];

int i=100;
Session[ "mySession "]=i;
int j=(int)Session[ "mySession "];
是同样道理
在gv控件的当前行的i列里包含一个CheckBox时,此转换才能成功。
[解决办法]
只是申明一个变量!接分
------解决方案--------------------


allen_cn(波波) ( ) 信誉:100 Blog 2007-03-15 11:45:11 得分: 0


drv[i],i是列的索引值


数据库里的,从0开始

读书人网 >asp.net

热点推荐