动态添加标签 [英] add tags dynamically

查看:61
本文介绍了动态添加标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
我在数据库中有一个表,该表由7个colms名称,open,close,low,high,target,currency组成.我有一个asp.net网页,它包含一个图像,在该图像上有3个文本框和4个标签.


我想要一种机械方法,也可以动态添加给定图像以及标签和文本框,从表中获取值并将其分配给这些标签和texbox.假设表中有20个输入项,则应在20个以上类型的图像上添加标签和文本框.

hi!
i have a table in database that consists of 7 colms name,open,close,low,high,target,currency. and i have an asp.net web page it consists an image, and on that image there are 3 textboxes and 4 lables.


what i want a machenism that add the given image dynamically also the lables and textboxes, takes the values from table and assign them to those lables and texboxes. suppose if there are 20 enteries in the table so 20 images of above type shuld be added with the labels and textboxes.
can somebody tells me how is it possible?

推荐答案

这是一个动态创建HTML控件的示例.
希望对您有帮助.
您可以在sb.AppendLine
中使用标签
This is an example to create HTML controls dynamically.
hope it helps you.
you can use tags in sb.AppendLine
public static System.Web.UI.HtmlControls.HtmlGenericControl select_Emp(Page p, string userid)
    {
        String[] ss=new String[6];
        SqlCommand cmd7 = new SqlCommand();
        cmd7.CommandText = "select_Emp";
        cmd7.CommandType = CommandType.StoredProcedure;
        cmd7.Connection = Db.GetConnection();
        cmd7.Parameters.AddWithValue("@userid", userid);
        SqlDataReader dr7 = cmd7.ExecuteReader();
        

        System.Web.UI.HtmlControls.HtmlGenericControl dynDiv =
        new System.Web.UI.HtmlControls.HtmlGenericControl("DIV cssClass='roundedPanel'");
        dynDiv.ID = "dynDivCode";
        dynDiv.Style.Add(HtmlTextWriterStyle.BackgroundColor, "Gray");
        dynDiv.Style.Add(HtmlTextWriterStyle.Height, "20px");
        dynDiv.Style.Add(HtmlTextWriterStyle.Width, "300px");
        //dynDiv.Controls.Add("Panel");
       // dynDiv.InnerHtml = "I was created using Code Behind";


        if (dr7.Read())
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Employee Name : " + dr7[0].ToString() + "");
            sb.AppendLine("Designation : " + dr7[1].ToString() + "<br />");
            sb.AppendLine("Department : " + dr7[2].ToString() + "");
            sb.AppendLine("Location : " + dr7[3].ToString() + "<br />");
            sb.AppendLine("Email ID : " + dr7[4].ToString() + "");
            sb.AppendLine("Office No. : " + dr7[5].ToString() + "");
            sb.AppendLine("Personal Contact No : " + dr7[6].ToString() + "");
            sb.AppendLine("Address : " + dr7[7].ToString() + "<br />");
            dynDiv.InnerHtml = sb.ToString();//Finally assign the dynamic value to the dynamic DIV
            p.Controls.Add(dynDiv);

        }

        return dynDiv;
    }


您可以为此使用DataRepeater控件.
you may use DataRepeater control for that.


这篇关于动态添加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆