Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
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

C#
<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);
}
Posted
Updated 16-Mar-11 4:37am
v2

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.
 
Share this answer
 
Comments
Yusuf 16-Mar-11 11:20am    
I've totally lost it. First of why does he need to confirm it? I am guessing it the question might not been well formed. He may be asking it is not hiding as it should be?

Second, what happens to the ages long of running the app to see what happens. Does he needs to confirm with someone first?

Again I may not have understood the question properly.
Sandeep Mewara 16-Mar-11 11:22am    
:)
mandarapu 16-Mar-11 11:29am    
it may be disable or not able to view also no problem.if i am logging with other id also it is in enable mode.i need it to disable.
mandarapu 16-Mar-11 11:30am    
i code what u modified i understand in that if what the condition i need to keep.
C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900