views:

74

answers:

2

hi, i am using detialsview control.here i have edit and delete button. i am using autogenerateitbutton="true" autogeneratedeletebuton="true"

now i have user role as **admin ** and normal user

in DB i table as user column roleID, here "1" is admin " 2" is normal user"

if the role type is admin(1) then show both edit and delete button if the role type is mormal(2) user then dnt show these two button for noprmal user how can i achive this functionlity done here in detialsview control

how can i get these controlID(i.e edit and delete button) in .cs file based on that i need to show the edit and delete button

any help would be great thank you

+1  A: 

There is a method called DetailsView.ChangeMode that Switches the DetailsView control to the specified mode i.e Edit or Delete or ReadOnly.

void Page_Load()  
    {
      if (IsPostBack == false)
      {
         if (roleid==1)
          {
           detailsView1.ChangeMode(DetailsViewMode.Edit);
          }
          else
          {
           detailsView1.ChangeMode(DetailsViewMode.ReadOnly);
          }
      }

     }
I Am Back
A: 

you can try like... I have tested this, will definitly work.

protected void dtv_DataBound(object sender, EventArgs e)
{
    //put your condition here for role check
    dtv.Rows[dtv.Rows.Count - 1].Visible = false;//since in the last row ur save/update buttons
}
Muhammad Akhtar