提供禁用选项以删除按钮 [英] giving disable option to delete button

查看:44
本文介绍了提供禁用选项以删除按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我对我的项目有疑问.

我只需要为授权用户提供一个启用删除按钮的选项.
对于其他人,它应该处于禁用模式.

拜托,谁能帮我.

我正在发布我的代码.
对我来说很紧急.

在此先感谢!

Hi,

I am having doubts regarding my project.

I need to give an enable option for delete button to only authorized users.
For others it should be in disabled mode.

Please, can any one help me.

I am posting my code.
Urgent for me.

thanks in advance!

protected void Page_Load(object sender, EventArgs e)
   {

       if (!IsPostBack)
       {

           FillGridView();

       }
   }

   private void FillGridView()
   {
                  DataSet ds = null;
           ConferenceBL confBL = new ConferenceBL();
           ds = confBL.GetConferenceRoom();
           ViewState["ds"] = ds;

           if (ds != null)
           {
               gvconference.Visible = true;
               gvconference.DataSource = ds;
               gvconference.DataBind();


           }
       }
          }

   protected void gvconference_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       try
      {
        gvconference.PageIndex = e.NewPageIndex;
        FillGridView();
      }

      catch (Exception ex)
      {
          if (log.IsErrorEnabled)
          {
              log.Error(ex.Message);
          }
      }
   }


   protected void gvconference_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       try
       {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string EmployeeId = Session["EmployeeId"].ToString();
                Button b = (Button)e.Row.FindControl("btnDelete");
              b.Attributes.Add("onclick", "javascript:return " +
             "confirm('Are you sure you want to delete this record " +
      DataBinder.Eval(e.Row.DataItem, "SequenceId") + "')");
                }
                            }

           }

       catch (Exception ex)
       {
           if (log.IsErrorEnabled)
           {
               log.Error(ex.Message);
           }
       }

   }

   protected void gvconference_RowCommand(object sender, GridViewCommandEventArgs e)
   {
                  if (e.CommandName == "Delete")
           {
               string EmployeeId = Session["EmployeeId"].ToString();
               int SequenceId = Convert.ToInt32(e.CommandArgument);

               // Delete the record
               DeleteRecordById(SequenceId,EmployeeId);




           }
       }
             }

   protected void gvconference_RowDeleting(object sender, GridViewDeleteEventArgs e)
   {
       try
       {

           int SequenceId = (int)gvconference.DataKeys[e.RowIndex].Value;
           string EmployeeId = Session["EmployeeId"].ToString();

           DeleteRecordById(SequenceId,EmployeeId);
       }
       catch (Exception ex)
       {
           if (log.IsErrorEnabled)
           {
               log.Error(ex.Message);
           }
       }
   }

   private void DeleteRecordById(int SequenceId,string EmployeeId)
   {
                 ConferenceBL confBL = new ConferenceBL();
           confBL.DeleteConferenceRoom(SequenceId,EmployeeId);
           FillGridView();
       


         }

推荐答案

protected void gvconference_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       try
       {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string EmployeeId = Session["EmployeeId"].ToString();
                Button b = (Button)e.Row.FindControl("btnDelete");
              b.Attributes.Add("onclick", "javascript:return " +
             "confirm('Are you sure you want to delete this record " +
      DataBinder.Eval(e.Row.DataItem, "SequenceId") + "')");
                }
//***********************************
if(CheckYourConditions)// Check for the condition here
{
 b.Enabled = true;
}
else
{
 b.Enabled = false;
}

//***********************************
                            }

           }

       catch (Exception ex)
       {
           if (log.IsErrorEnabled)
           {
               log.Error(ex.Message);
           }
       }

   }


在页面加载检查中,如果用户被授权,则是否被授权,

启用您的删除按钮否则会被禁用
in Page Load check User is authorized or not if he is authorized then

enabled Your delete button other wise make it disabled


所有取决于您如何实现授权.
在您的Page_Load中编写如下内容:

All depends how you have implemented an authorization.
Write in your Page_Load something like this:

//...
btnDelete.Enabled=IsAuthorized;
//...



并根据您的授权实施IsAuthorized属性.此属性对配置UI的其余部分很有用.



And implement IsAuthorized property depending your authorization. This property will be useful to configure the rest of UI.


这篇关于提供禁用选项以删除按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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