想实现将表中字段的值绑定到对应的CheckBox,即:如果字段值为1,则对应CheckBox为选中状态;如果值为0,则对应CheckBox为非选中状态。我用以下方法可调试时,执行到powersView.Checked;
出错:CS0201: 只有 assignment、call、increment、decrement 和 new 对象表达式可用作语句
***.aspx.cs:
private void PowersBind()
{
string users_Name = userslist.SelectedItem.Text.ToString();
Users users = new Users();
DataRow dr = users.GetPowersLoad(users_Name);
if(dr!=null)
{
if (dr["powers_View"].ToString() == "1")
{
powersView.Checked; }
if (dr["powers_Add"].ToString() == "1")
{
powersAdd.Checked;
}
if (dr["powers_Modi"].ToString() == "1")
{
powersModi.Checked;
}
if (dr["powers_Del"].ToString() == "1")
{
powersDel.Checked;
}
if (dr["powers_Check"].ToString() == "1")
{
powersCheck.Checked;
}
}
}
***.aspx:
<table style="width: 627px" border="1" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 130px; background-color: #eeeeee;">
<asp:Label ID="Label1" runat="server" Text="用户名"></asp:Label></td>
<td style="background-color: #eeeeee">
<asp:Label ID="Label2" runat="server" Text="浏 览"></asp:Label></td>
<td style="background-color: #eeeeee">
<asp:Label ID="Label3" runat="server" Text="添 加"></asp:Label></td>
<td style="background-color: #eeeeee">
<asp:Label ID="Label4" runat="server" Text="修 改"></asp:Label></td>
<td style="background-color: #eeeeee">
<asp:Label ID="Label5" runat="server" Text="删 除"></asp:Label></td>
<td style="background-color: #eeeeee">
<asp:Label ID="Label6" runat="server" Text="审 批"></asp:Label></td>
</tr>
<tr>
<td align="center" style="width: 130px">
<asp:DropDownList ID="userslist" runat="server" CssClass="DropDownList" Width="119px" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="users_Name" DataValueField="users_Id">
</asp:DropDownList></td>
<td align="center">
<asp:CheckBox ID="powersView" runat="server" /></td>
<td align="center">
<asp:CheckBox ID="powersAdd" runat="server" /></td>
<td align="center">
<asp:CheckBox ID="powersModi" runat="server" /></td>
<td align="center">