2012-06-28 5 views
0

사용자 ID를 수락하고 동일한 ID를 가진 프로젝트 소유자가 있는지 확인하고 싶습니다. 프로젝트 소유자가있는 경우 "아래로 이동"버튼을 사용하고 다른 모든 버튼은 비활성화해야합니다. 관리자가 있으면 모든 버튼이 활성화되고 첫 번째 이동은 위로 이동하고 마지막 이동은 아래로 이동합니다. POwner가 userID와 동일한 버튼 이외의 버튼을 모두 비활성화하고 싶습니다! 합니다 (POwner는 사용자 ID와 동일한 경우에만 버튼이 활성화되어야한다 아래로 이동합니다.로그인 한 사용자에 따라 버튼을 비활성화하십시오.

public void Repeater1_ItemDatabound(Object Sender, RepeaterItemEventArgs e) 
    { 

     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
     { 
      String userID = User.Identity.Name.Split('\\')[1]; 
      if (setvisibility(userID) == true) //Check if the person is Admin all buttons work 
      { 

       if (e.Item.ItemIndex == 0) 
       { 
        Button b = e.Item.FindControl("btnmoveup") as Button; 
        b.Enabled = false; 
       } 

       DataView view = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty); 
       DataTable result = view.ToTable(); 
       if (e.Item.ItemIndex == (result.Rows.Count) - 1) 
       { 
        Button b2 = e.Item.FindControl("btnmovedown") as Button; 
        b2.Enabled = false; 
       } 

      } 
      else // Check if Project Owner (POwner exists) Check if userID exists in POwner 
      { 
       using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["ctd_priority_dbConnectionString"].ConnectionString)) 
       { 
        connection.Open(); 
        SqlCommand cmd = new SqlCommand("Select POwner from Projects WHERE POwner = @userid", connection); 
        cmd.Parameters.AddWithValue("@userid", userID); 
        SqlDataReader reader = cmd.ExecuteReader(); 
+2

그리고 귀하의 질문은 무엇입니까? –

+0

은 asp-classic과 전혀 관련이 없습니다. – ulluoink

+0

POwner가 userID와 동일한 버튼 이외의 모든 버튼을 비활성화하고 싶습니다! – Pradit

답변

0

당신이 개 가능 역할

bool isAdmin; 
bool isProjectOwner; 

와 그 값에 대한 정보를가는 전에 을 결정하기위한 (로컬) 부울 변수를 만듭니다 당신의 버튼을 활성화/비활성화합니다.

isAdmin = setvisibility(userID); 
//isProjectOwner // create a similar method to setvisibility() for your project owner 

을 이제 단순히 할당 또는를 부정하여 버튼의 가시성을 전환 할 수 있습니다

private static void DisableButtonControls(RepeaterItemEventArgs e) 
    { 
     foreach (Control control in e.Item.Controls) 
     { 
      if (control is Button) 
      { 
       control.Visible = false; 
      } 
     } 
    } 

이를 사용하려면 : 당신이 다음 리피터 항목 템플릿 내부 모든 버튼을 해제하면 컨트롤을 비활성화 할 시점에서이 메서드를 호출하려고 할 경우 사용자의 역할은

... 
if (e.Item.ItemIndex == 0) 
{ 
    Button b = e.Item.FindControl("btnmoveup") as Button; 
    // IS NOT admin AND IS project owner will set .Enabled = true 
    b.Enabled = (!isAdmin && isProjectOwner); 
} 
0

상태 아래 버튼을 누르면 모든 버튼이 비활성화 된 후 수행 할 수 있습니다.

Button downButton = e.FindControl("btnmovedown") as Button; 
if (downButton != null) 
{ 
    downButton.Visible = false; 
} 

좋은 경험 법칙은 'as' 키워드를 사용하여 유형을 변환하면 반환 된 객체가 사용되기 전에 null이 아닌지 확인하십시오.

+0

그리고 POWner가 UserID와 일치하는 경우에만 아래쪽 버튼을 활성화하면 어떨까요? – Pradit

관련 문제