2

How do I access a particular row in asp Repeater and disable the buttons in it ? This program disables all the down buttons. I want to check if the userId exists in Database it should disable the up button and only the down button should be enabled.

  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 (isOwner(userID) == true)
             {

                 Button b = e.Item.FindControl("btnmoveup") as Button;
                    b.Enabled = false;


            }

public bool isOwner(string user_ID)
    {
        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", user_ID);
            SqlDataReader reader = cmd.ExecuteReader();

            if (reader.HasRows)
            {

                return true;
            }
            else
            {
                return false;
            }
            connection.Close();
        }
    }
4

1 回答 1

0

不是直接回答你的问题...

但是我用于启用、可见和其他属性的一种技术是将该值拉入您用来填充转发器的查询中。例如,您的查询/存储过程可能会返回一个名为“is_enabled”的列,其值为 1 或 0。然后你的按钮的 .enabled 属性可以这样设置:.enabled = '<%# eval(is_enabled) %>'

希望有帮助

于 2012-06-28T19:57:49.127 回答