一个值得借鉴的数据绑定函数

 public string getTableData(DataTable dt,string Model, params string[] columns)
        {

            System.Text.StringBuilder tempSb = new System.Text.StringBuilder("");
            if(dt!=null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    string[] tempStr = new string[columns.Length];
                    for (int i = 0; i < tempStr.Length; i++)
                    {
                        tempStr[i] = Convert.ToString(dr[columns[i]]);
                    }

                    tempSb.AppendFormat(Model, tempStr);
                }
            }
            return tempSb.ToString();
           
        }

   string tempCitySql = "select CityId,City from city where father='330000'";

  string tempCityModel = "<option value=\"{0}\">{1}</option>";

 this.tempCityData = getTableData(ds.Tables[0], tempCityModel, "City", "City");

 

 

 

一个值得借鉴的数据绑定函数

你可能感兴趣的:(数据绑定)