/// <summary> /// 用来将数据绑定到GridView的FooterRow中或DataRow中的下拉列表,绑定到FooterRow时,该方法一般放在使FooterRow显示的事件中,绑定到DataRow时,该方法一般放在GridView的RowDataBound事件中 /// </summary> /// <param name="tableName">表名</param> /// <param name="ddl">下拉列表名</param> /// <param name="ddlSelectedItemText">DropDownList选定项的文本</param> /// <param name="ddlSelectedItemValue">DropDownList选定项的值</param> /// <param name="condition">条件字符串</param> /// <param name="IsInsert0">是否插入值为0的行,真插入</param> public static void BindtoDropDownList(string tableName, DropDownList ddl, string ddlSelectedItemText, string ddlSelectedItemValue, string condition, string orderByCondition, bool IsInsert0) { Common common = new Common(); string sql = "select * from {0} where {1} order by {2} "; sql = string.Format(sql, tableName, condition, orderByCondition); DataSet ds = common.GetDataSet(sql); ddl.DataSource = ds.Tables[0].DefaultView; ddl.DataTextField = ddlSelectedItemText; ddl.DataValueField = ddlSelectedItemValue; ddl.DataBind(); if (IsInsert0) ddl.Items.Insert(0, new ListItem("--请选择--", "0")); }
public static DataTable GetDataTable(string Sql) { Common comm = new Common(); DataTable dt = comm.GetDataSet(Sql).Tables[0]; return dt; }
/// <summary> /// 绑定数据表中的前几条记录到Repeater /// </summary> /// <param name="tableName">被绑定数据的来源表的表名</param> /// <param name="whereCondition">执行查询的where条件</param> /// <param name="orderByCondition">查询结果的排序条件</param> /// <param name="repeater">要绑定数据的Repeater</param> /// <param name="TopCount">绑定的记录个数</param> public static void RepeaterBind(string tableName, string whereCondition, string orderByCondition, Repeater repeater, int TopCount) { string sql = "select * from {0} where {1} order by {2} Limit {3}"; sql = string.Format(sql, tableName, whereCondition, orderByCondition, TopCount); Common comm = new Common(); DataSet ds = comm.GetDataSet(sql); repeater.DataSource = ds.Tables[0].DefaultView; repeater.DataBind(); }
/// <summary> /// 根据id获取对应的中文名,此id为指定的表中主键字段对应的一个具体值 /// </summary> /// <param name="id">中文名对应的id的某个具体值</param> /// <param name="tableName">具有id与中文名对应关系的表名</param> /// <param name="tableRegion">id在表中对应的字段</param> /// <param name="chineseName">中文名在表中对应的字段</param> /// <returns></returns> public static string GetIdChineseName(int id, string tableName, string tableRegion, string chineseName) { string sql = "select * from " + tableName + " where " + tableRegion + " = " + id; Common common = new Common(); DataSet ds = common.GetDataSet(sql); if (ds.Tables[0].Rows.Count > 0) { DataTable dt = ds.Tables[0]; DataRow dr = dt.Rows[0]; return dr[chineseName].ToString(); } else return ""; }