gpt4 book ai didi

c# - 禁用 Repeater 中的按钮

转载 作者:太空宇宙 更新时间:2023-11-03 16:29:35 25 4
gpt4 key购买 nike

如何访问 asp Repeater 中的特定行并禁用其中的按钮?该程序禁用所有向下按钮。我想检查 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 (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();
}
}

最佳答案

不是您问题的直接答案...

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

希望对你有帮助

关于c# - 禁用 Repeater 中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11251894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com