当前位置: 移动技术网 > IT编程>开发语言>.net > .net 后台动态添加datalist 并绑定

.net 后台动态添加datalist 并绑定

2018年12月06日  | 移动技术网IT编程  | 我要评论

玩的就是陆虎,爱情动作片网站你懂的,5566网页

[csharp] 
public void getdatalistdata(string standardclass, string toothtypebig, int i) 
        { 
            datatable dt = binddata(standardclass, toothtypebig); 
            datalist d = new datalist(); 
            d.id = "dlsttest"; 
            d.itemtemplate = new mycolumn("litdata", 200); 
            d.repeatcolumns = 5; 
            d.repeatdirection = repeatdirection.horizontal; 
            d.itemdatabound += new datalistitemeventhandler(d_itemdatabound); 
            d.datasource = dt; 
            d.databind(); 
 
            htmlgenericcontrol p = new htmlgenericcontrol("p"); 
            p.attributes.add("class", "productintrolist"); 
            if (i == 0) 
                p.style.add("display", "block"); 
            else  
                p.style.add("display", "none"); 
            p.controls.add(d); 
            this.plist.controls.add(p); 
        } 
        private void d_itemdatabound(object sender, system.web.ui.webcontrols.datalistitemeventargs e) 
        { 
            literal t; 
            if (e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem) 
            { 
                t = (literal)e.item.findcontrol("litdata"); 
                if (t != null) 
                { 
                    string ulstring = string.format(@"<ul><li><a class='imageblock' href='productinfor.x?{0}'> 
                                            <img width='126px' height='106px' src='imgproduct/{1}' border='0' /></a> 
                                            <a class='textblock' href='productinfor.aspx?{0}'> {2}-{3}</a></li> 
                                       </ul>", ((datarowview)e.item.dataitem).row["url"].tostring(), ((datarowview)e.item.dataitem).row["imageurl"].tostring(), ((datarowview)e.item.dataitem).row["name"].tostring(), ((datarowview)e.item.dataitem).row["cdescription"].tostring()); 
                    t.text = ulstring; 
                } 
            } 
        } 
        public datatable binddata(string _standardclass, string _toothtypebig) 
        { 
            this.pshopnull.visible = false; 
            try 
            { 
                string sql = @"select distinct name,cdescription,standardclass,groove,headtype,toothtypebig from ba_shelltrumpet  where 1=1 "; 
                if (_standardclass != "") 
                { 
                    sql += "and standardclass='" + _standardclass + "'"; 
                } 
                if (_toothtypebig != "") 
                    sql += " and toothtypebig='" + _toothtypebig + "'"; 
                sql += "order by name"; 
                datatable standard = bll.getdatatable(sql); 
                if (!commonclass.dtrow.checkdtisempty(standard)) 
                { 
                    standard.columns.add("url", typeof(string)); 
                    standard.columns.add("imageurl", typeof(string)); 
                    for (int i = 0; i < standard.rows.count; i++) 
                    { 
                        //standardclass={0}&name={1}&cdescription={2} 
                        standard.rows[i]["url"] = "standardclass=" + standard.rows[i]["standardclass"].tostring() + "&name=" + standard.rows[i]["name"].tostring() + "&cdescription=" + standard.rows[i]["cdescription"].tostring() + "&groove=" + standard.rows[i]["groove"].tostring() + "&headtype=" + standard.rows[i]["headtype"].tostring() + "&toothtypebig=" + standard.rows[i]["toothtypebig"].tostring(); 
                        standard.rows[i]["imageurl"] = imageurl(standard.rows[i]["name"].tostring()); 
                    } 
                    return standard; 
                } 
                else 
                { 
                    this.pshopnull.visible = true; 
                    return null; 
                } 
 
            } 
            catch (exception ex) 
            { 
 
                throw; 
                return null; 
            } 
 
        } 
        public class mycolumn : itemplate 
        { 
            private string pcontrolname; //控件名称   
            private int pwidth; //控件宽度   
            public mycolumn(string controlname, int width) 
            { 
                pcontrolname = controlname; 
                pwidth = width; 
            } 
            public void instantiatein(control container) 
            { 
                literal h = new literal(); 
                h.id = pcontrolname; 
                container.controls.add(h); 
            } 
        } 
        public string imageurl(string name) 
        { 
            if (name == "") 
                return "no_pic.jpg"; 
            string imagename = "imgproduct\\" + name + ".jpg"; 
            string path = system.web.httpcontext.current.server.mappath(imagename); //webhelper.getsiteurl() + "\\" + imagename; 
            if (system.io.file.exists(path)) 
            { 
                return name + ".jpg"; 
            } 
            return "no_pic.jpg"; 
        } 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网