关于GridView中的删除按钮的疑问 [英] doubt regarding delete button in gridview

查看:39
本文介绍了关于GridView中的删除按钮的疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在我的项目中按其要求执行一项任务,因为我编写了用于会议室预定的代码.预订中有哪些详细信息将显示在gridview.for中,我编写了代码,并且工作正常,而且我还需要删除gridview中的特定行.对于gridview中的删除行,我向预订者提供了删除选项该room.for其他人将无法正常工作,但其他人的按钮也处于启用模式.现在,我希望其他人禁用该按钮,否则该按钮将无法查看.
请检查我发布的代码并建议我


i am doing one task in my project as their requirements in that i wrote the code for booking of the conferenceroom. what details in that booking will display in the gridview.for that i wrote the code and also it is working fine and also i need to delete the particular row in gridview.for that delete row in gridview i gave delete option to the persons who books the room.for others it wont work but button is in enable mode for other persons also.now i want that button to be disable for others or it should not be able to view.
please check the code i posted and suggest me

<asp:GridView DataKeyNames="SequenceId" ID="gvconference" runat="server"
AllowPaging="True" Width="99%"
PageSize="10" CssClass="gridbdr"
AllowSorting="True" AutoGenerateColumns="False"
onpageindexchanging="gvconference_PageIndexChanging"
onrowdatabound="gvconference_RowDataBound"
onrowcommand="gvconference_RowCommand"
onrowdeleting="gvconference_RowDeleting"
onrowdeleted="gvconference_RowDeleted" Visible="False">


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

if (e.Row.RowType == DataControlRowType.DataRow)
{


Button b = (Button)e.Row.FindControl("btnDelete");
b.Visible = true;

b.Attributes.Add("onclick", "javascript:return " +
"confirm(''Are you sure you want to delete this record " +
DataBinder.Eval(e.Row.DataItem, "SequenceId")+ "'')");
}

}

protected void gvconference_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
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);
}

推荐答案

现在我希望其他人禁用该按钮,否则该按钮将无法查看.
只需在行数据绑定事件中将其禁用或隐藏即可.看来您已经做到了.

现在吗?

如果您要确认,那就可以了.看起来不错.
now i want that button to be disable for others or it should not be able to view.
Just disable or hide it in the row data bound event. Looks like you have already done that.

Now?

If you are confirming, then that''s ok. It looks good.


if (e.Row.RowType == DataControlRowType.DataRow)
{

//Check if user can delete it
string EmployeeId = Session["EmployeeId"].ToString();
//Get the Employee Object
//Check if user can delete this row

Button b = (Button)e.Row.FindControl(&quot;btnDelete&quot;);
if (user can delete the row)
{
  b.Visible = true;
  b.Attributes.Add("onclick", "javascript:return " +
  "confirm('Are you sure you want to delete this record " +
  DataBinder.Eval(e.Row.DataItem, "SequenceId")+ "')");
}
else
{
  b.Visible = false;
}
}



您不需要检查用户是否可以删除项目吗?我只会让那些有权删除它的用户看到它.



Don''t you need to check if the user can delete the item? I would only make it visible for those users who are authorized to delete it.


这篇关于关于GridView中的删除按钮的疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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