在CheckBoxList后面加文字

小丫头 2011-01-11 04:13:19
我绑定是的数据库字段Months 现在是varchar类型的
绑定的数据是 1、2、3、4、5、6、7、8、9、10、11、12
我要显示的是 1月份、2月份、3月份、4月份、5月份、6月份、7月份、8月份、9月份、10月份、11月份、12月份

string sqlstr = "select distinct(Months)+'月份' from Report";//报错:不包含名为“Months”的属性
DataSet ds = db.GetDS(sqlstr);
this.CheckBoxList1.DataSource = ds;
this.CheckBoxList1.DataTextField = "Months";
this.CheckBoxList1.DataValueField = "Months";
this.CheckBoxList1.DataBind();

应该怎么办呢?
...全文
132 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
冬雨在路上 2011-01-11
  • 打赏
  • 举报
回复
string[] a = new string[dataTable.Rows.Count];
for (int i = 0; i<dataTable.Rows.Count; i++)
{
a[i] = dataTable.Rows[i]["month"].ToString() + "月";
}
DataTable dt = new DataTable();
dt.Columns.Add(ColumnName, typeof(string));

for (int i = 0; i < a.Length; i++)
{
DataRow dr = dt.NewRow();
dr[ColumnName] = a[i].ToString();
dt.Rows.Add(dr);
}
//然后绑定dt
冬雨在路上 2011-01-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 koukoujiayi 的回复:]
string sqlstr = "select Months+'月份' as 'Months' from Report";//
[/Quote]

在MySQL里sql语句:select Months+'月份' as 'Months' from Report";不行
koukoujiayi 2011-01-11
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 qq116927181 的回复:]
C# code
string sqlstr = "select distinct(Months)+'月份' as Months from Report";//

这个方法确实不错啊,不过我点按钮的时候就 报错: '月份' 附近有语法错误。
[/Quote]
你的Months是数值型,转换一下!
string sqlstr = "select distinct Convert(varchar(2),Months)+'月份' as Months from Report";//

加油馒头 2011-01-11
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 qq116927181 的回复:]
C# code
string sqlstr = "select distinct(Months)+'月份' as Months from Report";//

这个方法确实不错啊,不过我点按钮的时候就 报错: '月份' 附近有语法错误。
[/Quote]

select distinct(Months)||'月份' as Months from Report
冬雨在路上 2011-01-11
  • 打赏
  • 举报
回复
你可以多所有的checkboxlist用foreach循环加月份

加油馒头 2011-01-11
  • 打赏
  • 举报
回复
string sqlstr = "select distinct(Months)+'月份' from Report";//报错:不包含名为“Months”的属性

select distinct(Months)+'月份' as Months from Report
小丫头 2011-01-11
  • 打赏
  • 举报
回复
string sqlstr = "select distinct(Months)+'月份' as Months from Report";//

这个方法确实不错啊,不过我点按钮的时候就 报错: '月份' 附近有语法错误。

  • 打赏
  • 举报
回复
string sqlstr = "select Months+'月份' as 'Months' from Report";//
叶子 2011-01-11
  • 打赏
  • 举报
回复

string sqlstr = "select distinct(Months)+'月份' as Months from Report";//这样就可以了
DataSet ds = db.GetDS(sqlstr);
this.CheckBoxList1.DataSource = ds;
this.CheckBoxList1.DataTextField = "Months";
this.CheckBoxList1.DataValueField = "Months";
this.CheckBoxList1.DataBind();



koukoujiayi 2011-01-11
  • 打赏
  • 举报
回复
string sqlstr = "select Months+'月份' as 'Months' from Report";//
小丫头 2011-01-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jayinit 的回复:]
要不就遍历checksbox的文本吧,每个都加上,不在SQL中加了
在SQL中应该也行的,你写的错了
[/Quote]
我知道我写错了,应该怎么写呢?
  • 打赏
  • 举报
回复
要不就遍历checksbox的文本吧,每个都加上,不在SQL中加了
在SQL中应该也行的,你写的错了

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧