0

我有一个中继器,在它的 item_command 事件中我正在绑定另一个中继器。我想根据第二个中继器中的角色显示数据。为此,我想根据用户的角色隐藏和显示一些列。我们如何使用后面的代码来做到这一点。提前致谢。我的代码是

<table id="table1" class="yui" cellpadding="0" cellspacing="0">
                <thead>
                    <tr>
                        <th>
                            <a href='#' title="Click Header to Sort">EmpID #</a>
                        </th>
                        <th>Edit</th>
                    </tr>
                </thead>
                <tbody>
                    <asp:Repeater ID="Repaddressorbbl" runat="server" OnItemCommand="Repaddressorbbl_ItemCommand">
                        <ItemTemplate>
                           <tr id="gh" style="cursor: pointer" onclick="Select(this);">
                                <td style="text-align: center;">
                                    <%#Eval("empid")%>
                                </td>  
                                <td>
                                    <asp:LinkButton ID="lknumber" runat="server" Text="Edit" CommandName="searchbybbloraddress" />
                                </td>                             
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </tbody>
                <tfoot>
                </tfoot>
            </table>

 protected void Repaddressorbbl_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "searchbybbloraddress")
        {
          bind_rep2(); 
        }
    }
4

2 回答 2

0

简单的方法是使用 javascript 并在隐藏和创建函数时使用 Display:none,即在需要时显示它。

于 2011-11-15T11:29:28.373 回答
0

如果您想在后面的代码中从 ItemCommand 数据绑定第二个中继器,您有两个选择。

您可以修改您设置为第二个中继器的 DataSource 的数据集,并将敏感数据设置为空字符串或* *。

The other option you have is add a IsVisibleToUser boolean property to your dataset and in your second repeater bind the Visible property to this property.

You can easily modify the data that is given to your DataSource by using a Linq query that produces an anonymous object.

Something like:

Repeater2.DataSource = from d in MyData
                       select new
{
    FirstName = d.FirstName,
    LastName = d.LastName,
    Salary = d.Salary,
    IsVisibleToUser = CurrentUser.IsInRole(...)
}
于 2011-11-15T11:34:17.563 回答