我想实现的功能是:repeater中有一列是“查看详情” 如果这一行数据没有添加详细信息则 “查看详情”下面的按钮时不可用的,如果有则可以点击。  (那位大侠做过类似的功能,麻烦您给贴出来点代码后给个例子。)

解决方案 »

  1.   

    本帖最后由 net_lover 于 2010-08-27 16:43:31 编辑
      

  2.   


    在Repeater1_ItemCommand事件里写实试过了。 不行,要先点击一下,才能发现能不能用。
      

  3.   

    1楼不是已经写了么,在ItemDataBound事件里就处理掉,而不是在ItemCommand事件里处理。
      

  4.   

    我把我写的代码给大家贴出来:public partial class anniu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                bind();
            }
        }
        public void bind()
        {        string sql = "select * from T_x";
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
            SqlCommand com = new SqlCommand(sql, con);        DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = com;
            da.Fill(ds);        this.Repeater1.DataSource = ds;
            this.Repeater1.DataBind();    }
        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            //if (e.CommandName == "look")
            //{ 
            //    //Button bt = ((Button)e.Item.FindControl("but"));           
            //    //string aa = Convert.ToString(bt.Text);            
            //    //Response.Write(aa);                     //}
        }
        protected void Repeater1_DataBinding(object sender, EventArgs e)
        {
            ////这注释的原因是报错。报出:“System.EventArgs”并不包含“Item”的定义
            ////Label lb = ((Label)e.Item.FindControl("Lbl"));
            ////int aa = Convert.ToInt32(lb.Text);                //string strsql = "select * from T_xx where ID=" + aa;
            //SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
            //SqlCommand com1 = new SqlCommand(strsql, con1);
            //DataSet dss = new DataSet();
            //SqlDataAdapter daa = new SqlDataAdapter();
            //daa.SelectCommand = com1;
            //daa.Fill(dss);        //if (dss.Tables[0].Rows.Count > 0)
            //{
            //    Button bu = ((Button)e.Item.FindControl("but"));
            //    bu.Enabled = true;
            //}
            //else
            //{
            //    Button bu = ((Button)e.Item.FindControl("but"));
            //    bu.Enabled = false;
            //}    }
        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //单步调试的结果是 lb=null
           Label lb = ((Label)e.Item.FindControl("Lbl"));       
            int aa = Convert.ToInt32(lb.Text);             string strsql = "select * from T_xx where ID=" + aa;
            SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
            SqlCommand com1 = new SqlCommand(strsql, con1);
            DataSet dss = new DataSet();
            SqlDataAdapter daa = new SqlDataAdapter();
            daa.SelectCommand = com1;
            daa.Fill(dss);        if (dss.Tables[0].Rows.Count > 0)
            {
                Button bu = ((Button)e.Item.FindControl("but"));
                bu.Enabled = true;
            }
            else
            {
                Button bu = ((Button)e.Item.FindControl("but"));
                bu.Enabled = false;
            }
        }
    }
      

  5.   

    在判断里面给按钮加enabled属性就可以了。
    按钮.Enabled = false;这是禁用true就是启用
      

  6.   

    <asp:Label ID="lbl" runat="server" Visible
    ='<%# Check((int)Eval("a")) %>'></asp:Label>
    protected bool Check(int value)
    {
      return true;
    }
      

  7.   

    运用js。在后台写一个public方法。