日期:2014-05-17  浏览次数:20463 次

让Label在页面载入时显示SQLDatesource取得的数据,错在哪里?
本帖最后由 linjiangxian11 于 2013-05-15 16:39:25 编辑
我要在加载页面时,给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> ";

    }

------解决方案--------------------
    自己解决了!但是换了一种方法:利用后台直接写sql语句!就行了!曲线救国!