让Label在页面载入时显示SQLDatesource取得的数据,错在哪里?

linjiangxian11 2013-05-15 04:38:44
我要在加载页面时,给Label添加一个数值。这个数值我用SQLDateSource数据源来取值,然后把取出来的值LastContractNumber添加到Label上去。
下面是我的代码,不知道错在哪里了!


------------------前台--------------------
<asp:Label ID="Label_0102" runat="server" Height="21px" Width="150px"></asp:Label>

<asp:SqlDataSource ID="SqlDataSource_LastContractNumber" runat="server"
ConnectionString="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString %>" SelectCommand="select top(1) ContractNumber as LastContractNumber
from ContractTable
where ContractNumber like '%csdy-ctwy-%'
order by ContractNumber desc"></asp:SqlDataSource>


-------------------后台-------------------

protected void SqlDataSource_LastContractNumber_Load(object sender, EventArgs e)
{
string count = e.Command.Parameters["LastContractNumber"].Value.ToString();
((Label)this.FormView1.FindControl("Label_0102")).Text = "共有:<span style='color:red;'>" + count + "</span> ";

}
...全文
77 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
linjiangxian1107 2013-10-24
  • 打赏
  • 举报
回复
自己解决了!但是换了一种方法:利用后台直接写sql语句!就行了!曲线救国!

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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