使用会员 ASP:NET 检查复选框
我有一个 GirdView 使用 ASP:NET 成员身份监听系统中所有活动的用户。 我想要一个可以选择或不选择的复选框,具体取决于特定用户是否已批准。 使用事件处理程序 RowDataBound,我的脚本不起作用。 知道在适当的情况下选择复选框吗?
感谢您的宝贵时间:-)
protected void uxUserListDisplayer_RowDataBound(object sender, GridViewRowEventArgs e)
{
// Check or Uncheck a CheckBox depending if user is Approved
switch (e.Row.RowType)
{
// In case type of row is DataRow (a data row of GridView)
case DataControlRowType.DataRow:
// Create an object of type MembershipUser for row bounded (Users)
MembershipUser myUser = (MembershipUser)e.Row.DataItem;
// Find out the edit button "uxLinkEditButton" and create an object for it
LinkButton editButton = (LinkButton)e.Row.FindControl("uxLinkEditButton");
// Find out the checkbox "uxActiveCheckBoxSelector" and create an object for it
CheckBox activeCheckBox = (CheckBox)e.Row.FindControl("uxActiveCheckBoxSelector");
// Check if the Object type MembershipUser for a User is approved or not
if (myUser.IsApproved == true)
{
activeCheckBox.Checked = true; // Checkbox is checked
}
else
{
activeCheckBox.Checked = false; // Checkbox is unchecked
}
break;
}
}
I have a GirdView listening all Users active in my system using ASP:NET Membership.
I would like have a CheckBox that could be SELECTED or NOT depending if a specific user is APPROVED or not.
With event handler RowDataBound, my script does not work.
Any idea to selected the CheckBox in the appropirate case?
Thanks for your time :-)
protected void uxUserListDisplayer_RowDataBound(object sender, GridViewRowEventArgs e)
{
// Check or Uncheck a CheckBox depending if user is Approved
switch (e.Row.RowType)
{
// In case type of row is DataRow (a data row of GridView)
case DataControlRowType.DataRow:
// Create an object of type MembershipUser for row bounded (Users)
MembershipUser myUser = (MembershipUser)e.Row.DataItem;
// Find out the edit button "uxLinkEditButton" and create an object for it
LinkButton editButton = (LinkButton)e.Row.FindControl("uxLinkEditButton");
// Find out the checkbox "uxActiveCheckBoxSelector" and create an object for it
CheckBox activeCheckBox = (CheckBox)e.Row.FindControl("uxActiveCheckBoxSelector");
// Check if the Object type MembershipUser for a User is approved or not
if (myUser.IsApproved == true)
{
activeCheckBox.Checked = true; // Checkbox is checked
}
else
{
activeCheckBox.Checked = false; // Checkbox is unchecked
}
break;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
希望这有帮助
Hope this helps
您必须将 myUser 变量更改为 MembershipUser 引用;默认情况下,对象没有定义属性...
HTH。
You have to change the myUser variable to a MembershipUser reference; by default, Object doesn't have the property defined...
HTH.