gridview编辑,删除等控制 [英] gridview editing,deleting etc. controlling

查看:73
本文介绍了gridview编辑,删除等控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在创建一个使用gridview控件的网站.我想保护我的网站.

因此,我希望只有某些指定用户(例如admin)才能更改gridview(如插入,更新和删除).

这些字段对于所有其他字段都是不可见的.

那我该怎么解决呢?

请帮帮我.

在此先感谢.

最好的问候,

Golam kibria

Hi All,

I am creating a website where I am using a gridview control.I want to secure my website.

So I want that only some specified users such as admin can change the gridview like inserting,updating and deleting.

These field will be invisible to all the others.

So how can I solve it?

Please help me.

Thanks in Advance.

Best Regards,

Golam kibria

推荐答案

您好,

不知道您的意思是这些字段对于其他所有字段都是不可见的"

但是,如果您有兴趣控制对网格视图的访问,请执行以下操作:

我假设您有某种用户信息对象,其中包含当前用户的详细信息(其访问权限,即标准的CRUD(创建,读取,更新,删除))

若要控制用户是否可以更新行,可以从DataGridView处理RowValidating事件,检查当前用户是否具有更新行的权限,如果没有,则将事件参数的Cancel属性设置为是的.

例如:

Hi there,

Not sure what you mean by "these field will be invisible to all others"

But if you are interested in controlling access to the grid-view:

I am assuming that you have some sort of user-info object that holds the current user''s details (their access rights, ie the standard CRUD (Create, Read, Update, Delete))

To control whether a user can update a row, you might handle the RowValidating event from the DataGridView, check if the current user has permission to update the row, and if they don''t, set the Cancel property of the event-arguments to True.

eg:

void grid_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
    if (!CurrentUser.CanUpdate())
        e.Cancel = true;

}




在数据网格视图上有很多事件,很多事件可以取消->那就是我要做的.


干杯,

Simon.




There are lots of events on the data-grid-view, a lot of them can be cancelled -> that is how I would do it.


Cheers,

Simon.


希望 [ ^ ]可能会帮助您.
Hope this[^] might help you.


Gridview的User RowDataBound事件.

User RowDataBound event of Gridview.

protected void gvr_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
       if ((e.Row.RowState & DataControlRowState.Edit) > 0)
       {
            Button btn = (Button)e.Row.Cells[6].FindControl("btnEdit");
            if(Session["UserType"].Equals("Admin"))//Checking whether the user is Admin or not
            {
              btn.Attributes.Add("style", "this.disabled=false;");
            }
            else
            {
              btn.Attributes.Add("style", "this.disabled=true;");
            }
       }
   }
}



您也可以使用display属性来隐藏/显示按钮.



Also you can use display attribute to hide/show the buttons.


这篇关于gridview编辑,删除等控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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