ASP.NET(C#) 开发WebForm现在想在DataGrid中动态控制某些列的只读属性。如:DataGrid中有“学号”“姓名”“科目”“成绩”“爱好”五个列。
对于学生用户,那么前四列是在只读的;对于老师,那么“爱好”是只读的。请问各位大侠有没有办法实现该功能?请指点……学习,关注!
对于学生用户,那么前四列是在只读的;对于老师,那么“爱好”是只读的。请问各位大侠有没有办法实现该功能?请指点……学习,关注!
</asp:BoundColumn>
你说的我也知道啊,我现在需要动态的控制只读属性请帮忙,谢谢!学习,关注……
用 TemplateColumn 调用这个方法就可以了
</asp:BoundColumn>
在datagrid中进行列的绑定,在BoundColumn中把属性 ReadOnly设为True,就是上面的意思。
'判斷是否是資料列
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
If flag_Confrim.Text.Trim <> "2" Then 寫你自己的判斷條件
e.Item.Cells(0).Enabled = False
e.Item.Cells(1).Enabled = False
Else
e.Item.Cells(0).Enabled = True
e.Item.Cells(1).Enabled = True
End If
End If
End Sub