我正在接受一个用户 ID,并想检查是否有任何项目所有者具有相同的 ID。如果存在项目所有者,我应该只启用“下移”按钮并禁用所有其他按钮。如果存在管理员,则除了第一个上移和最后一个下移之外,所有按钮都将启用。我想禁用除 POwner 与 userID 相同的所有按钮!(如果 Powner 与 UserID 相同,则应启用下移按钮。
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();