动态图像按钮不在asp.net中显示图像

时间:2017-08-11 07:50:53

标签: c# asp.net webforms

图像按钮是从数据库接收图像的路径,但它没有在图像按钮中显示它。而不是在它的网页中显示图像,它显示提交查询文本。

 protected void Page_Load(object sender, EventArgs e)
    {
        generateCategory();
    }

 public void generateCategory()
        {
            List<string> liCat = category();
            for(int i=0;i<category().Count; i++)
            {
                //HtmlAnchor ha = new HtmlAnchor();
                ImageButton imCat = new ImageButton();
                imCat.ID = "ImageCat" + i.ToString();
               // imCat.AlternateText = liCat[i].ToString();
                imCat.ImageUrl = liCat[i].ToString();
                //imCat.Attributes.Add("Class",);
                imCat.CssClass = "iMageButton";
                //ha.Controls.Add(imCat);
                panelControl.Controls.Add(imCat);
            }
        }
        public List<string> category()
        {
            List<string> catList = new List<string>();
            string query = "select Images from Category";
            SqlConnection con = new SqlConnection(cs);
            SqlCommand cmd = new SqlCommand(query, con);

            cmd.CommandType = CommandType.Text;
            con.Open();
            using (SqlDataReader rdr = cmd.ExecuteReader())
            {
                while (rdr.Read())
                {
                  //  catList.Add(rdr["CategoryName"].ToString());
                    catList.Add(rdr["Images"].ToString());
                }
            }
            return catList;
        }[Image path in imCat.ImageUrl ][1]

0 个答案:

没有答案