欢迎访问 生活随笔!

尊龙游戏旗舰厅官网

当前位置: 尊龙游戏旗舰厅官网 > 编程语言 > asp.net >内容正文

asp.net

asp.net服务器控件数据绑定总结 -尊龙游戏旗舰厅官网

发布时间:2025/1/21 asp.net 19 豆豆
尊龙游戏旗舰厅官网 收集整理的这篇文章主要介绍了 asp.net服务器控件数据绑定总结 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1 using system; 2 using system.collections.generic; 3 using system.text; 4 using system.web.ui.webcontrols;// 5 using system.data.sqlclient; 6 using system.data;// 7 using system.web.ui;// 8 using wuqi.webdiyer;//此控件请在网上下载 9 10 namespace study 11 { 12 public sealed class webcontrolsbind 13 { 14 #region dropdownlist 绑定 49 /// 50 /// 绑定dropdownlist控件 51 /// 52 /// 控件 53 /// 数据源 54 /// 文本值 55 /// 56 /// 是否包含全部项,若不包含返回false,若包含返回true 57 public static void bindddl(datatable p_drsource, dropdownlist p_ddlcontrol, string p_strtext, string p_strvalue, bool p_blall) 58 { 59 p_ddlcontrol.datasource = p_drsource; 60 p_ddlcontrol.datatextfield = p_strtext; 61 p_ddlcontrol.datavaluefield = p_strvalue; 62 p_ddlcontrol.databind(); 63 if (p_blall == true) 64 { 65 listitem li = new listitem("全部", "0"); 66 p_ddlcontrol.items.insert(0, li);//使用add方法只能添加到最后,使用insert方法可以添加到指定的位置 67 68 } 69 } 70 71 #endregion 72 73 #region 带分页的数据绑定repeater控件 74 /// 75 /// 带分页的repeater的数据绑定 76 /// 77 /// 数据源 78 /// repeater控件 79 /// 分页控件 80 public static void bindrpt(datatable dssource, repeater rpt, aspnetpager anp) 81 { 82 dataview dv = dssource.defaultview; 83 anp.recordcount = dv.count; 84 if (dv.count > 0) 85 { 86 pageddatasource pds = new pageddatasource(); 87 pds.datasource = dv; 88 pds.allowpaging = true; 89 pds.currentpageindex = anp.currentpageindex - 1; 90 pds.pagesize = anp.pagesize; 91 rpt.datasource = pds; 92 rpt.databind(); 93 94 } 95 96 97 } 98 public static void bindrpt(datatable dssource, repeater rpt, aspnetpager anp,string order) 99 { 100 dataview dv = dssource.defaultview; 101 dv.sort = order; 102 datatable dt = dv.totable(); 103 anp.recordcount = dv.count; 104 if (dv.count > 0) 105 { 106 pageddatasource pds = new pageddatasource(); 107 pds.datasource = dv; 108 pds.allowpaging = true; 109 pds.currentpageindex = anp.currentpageindex - 1; 110 pds.pagesize = anp.pagesize; 111 rpt.datasource = pds; 112 rpt.databind(); 113 114 } 115 116 117 } 118 119 #endregion 120 #region 带分页的数据绑定datalist控件 121 /// 122 /// 带分页的repeater的数据绑定 123 /// 124 /// 数据源 125 /// datalist控件 126 /// 分页控件 127 public static void binddlt(datatable dssource, datalist dlt, aspnetpager anp) 128 { 129 dataview dv = dssource.defaultview; 130 anp.recordcount = dv.count; 131 if (dv.count > 0) 132 { 133 pageddatasource pds = new pageddatasource(); 134 pds.datasource = dv; 135 pds.allowpaging = true; 136 pds.currentpageindex = anp.currentpageindex - 1; 137 pds.pagesize = anp.pagesize; 138 dlt.datasource = pds; 139 dlt.databind(); 140 141 } 142 143 144 } 145 146 147 #endregion 148 149 150 151 152 153 } 154 }

 

与50位技术专家面对面20年技术见证,附赠技术全景图

总结

以上是尊龙游戏旗舰厅官网为你收集整理的asp.net服务器控件数据绑定总结的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得尊龙游戏旗舰厅官网网站内容还不错,欢迎将尊龙游戏旗舰厅官网推荐给好友。

网站地图