1 void JustDisplay() 2 { 3 DataTable dt = sql.ExecuteDataset("select * from 核准审批表 where 预约登记号 in (select 预约登记号 from 现场审查表 where id=" + Request.QueryString["id"] + ")"); 4 if (dt.Rows.Count > 0) 5 { 6 DataRow ds = dt.Rows[0]; 7 foreach (Control c in divone.Controls) 8 { 9 if (c.GetType().Name == "Literal") 10 { 11 Utility.SetZhi(c, ds[c.ID].ToString()); 12 } 13 }
1 public class Utility 2 { 3 /// <summary> 4 /// 获取控件的值 5 /// </summary> 6 /// <param name="c">控件</param> 7 /// <returns></returns> 8 public static string GetZhi(Control c) 9 { 10 string rt = ""; 11 if (c.GetType().Name == "HiddenField") rt = Utility.AntiSqlText(((HiddenField)c).Value); 12 if (c.GetType().Name == "Label") rt = Utility.AntiSqlText(((Label)c).Text); 13 if (c.GetType().Name == "TextBox") rt = Utility.AntiSqlText(((TextBox)c).Text); 14 if (c.GetType().Name == "DropDownList") rt = Utility.AntiSqlText(((DropDownList)c).SelectedValue); 15 if (c.GetType().Name == "RadioButtonList") rt = Utility.AntiSqlText(((RadioButtonList)c).SelectedValue); 16 if (c.GetType().Name == "FCKeditor") rt = ((FredCK.FCKeditorV2.FCKeditor)c).Value.Replace("'", "''"); 17 if (c.GetType().Name == "CheckBoxList") 18 { 19 CheckBoxList cl = (CheckBoxList)c; 20 foreach (ListItem i in cl.Items) 21 if (i.Selected) rt += i.Value + ","; 22 rt = rt.TrimEnd(','); 23 } 24 return rt; 25 } 26 /// <summary> 27 /// 为控件的赋值 28 /// </summary> 29 /// <param name="c">控件</param> 30 /// <param name="zhi">值</param> 31 /// <returns></returns> 32 public static string SetZhi(Control c, string zhi) 33 { 34 string rt = ""; 35 if (c.GetType().Name == "HiddenField") ((HiddenField)c).Value = zhi; 36 if (c.GetType().Name == "TextBox") 37 { 38 TextBox tb = ((TextBox)c); 39 if (tb.TextMode == TextBoxMode.MultiLine) 40 tb.Text = zhi.Replace("\r", "").Replace(" ", " "); 41 else 42 tb.Text = zhi; 43 } 44 if (c.GetType().Name == "Label") ((Label)c).Text = zhi; 45 if (c.GetType().Name == "Literal") ((Literal)c).Text = zhi; 46 if (c.GetType().Name == "DropDownList") ((DropDownList)c).SelectedValue = zhi; 47 if (c.GetType().Name == "RadioButtonList") ((RadioButtonList)c).SelectedValue = zhi; 48 if (c.GetType().Name == "FCKeditor") ((FredCK.FCKeditorV2.FCKeditor)c).Value = zhi; 49 if (c.GetType().Name == "CheckBoxList") 50 { 51 CheckBoxList cl = (CheckBoxList)c; 52 foreach (ListItem i in cl.Items) 53 { 54 i.Selected = false; 55 if (zhi.Contains(i.Value)) i.Selected = true; 56 } 57 } 58 return rt; 59 }
未解决,关闭问题。
你这代码666
说明zjtyp1这个字段没有在DataTable中,快速跟踪看看
c.ID是你控件的ID值吧(也就是错误提示里面的zjtype1),但是从你的sql语句来看,所有的列估计都是中文命名的,也就是说你的ds(DataRow)中没有用英文字母命名的列zjtype1. 你把ds索引里面的列明改成固定的要的字符串就好了
太简单的问题,懒得回答了!