GridView仅在用户拥有记录的情况下显示命令字段! [英] GridView show command field only if user owns the record!

查看:69
本文介绍了GridView仅在用户拥有记录的情况下显示命令字段!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我希望网格视图仅针对这些记录显示命令字段(编辑,删除)
由当前登录的用户拥有.

谢谢!

Hi,

I want a grid view to show command field(edit, delete) against those records only
which are owned by the user that is currently logged-in.

Thanks!

推荐答案

在gridview的onRowDataBoundEvent中,您可以检索DataRowView.如果数据中包含用户标识(即使该字段未在gridview中显示!),则可以检查该用户标识是否与登录用户相同.
比在gridviewrow上执行findControl并将控件设置为visible = true或false.

在我的示例中,根据DataRowView中的值将工具提示添加到图像.

in the onRowDataBoundEvent of the gridview you can retrieve the DataRowView. If the userid is in the data (even if that field is not shown in your gridview!) you can then check if the userid is the same as the logged in user.
Than do a findControl on the gridviewrow and set the control to visible = true or false.

in my example a tooltip is added to an image based on a value in the DataRowView.

protected void grdAppSettingsORDB(Object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType.Equals(DataControlRowType.DataRow))
        {
            DataRowView dataRow = (DataRowView)e.Row.DataItem;
            Image imgHelp = (Image)e.Row.FindControl("imgHelp");
            if (null != imgHelp)
            {
                imgHelp.ToolTip = dataRow["Description"].ToString();
            }
        }
    }


这篇关于GridView仅在用户拥有记录的情况下显示命令字段!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆