首页 新闻 赞助 找找看

求解:怎么读取gridview模板ItemTemplate的label控件,并实现label值的绑定

0
[待解决问题]

Label4的值,是计算一个count,(这个count是下图得出的,而不是gridview的列!!)讲count的值赋值给label4.text。

图二是我想要的,count的一个方法,

这个方法是不是有错?

求正确的方法,并且结合图一,将label4.text显示为计算的count值。。。。

语夫子的主页 语夫子 | 菜鸟二级 | 园豆:204
提问于:2012-04-24 20:37
< >
分享
所有回答(1)
0

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

        Label lbl4= (Label)e.Row.FindControl("Label4");

用gridview的绑定方法,知道怎么弄了吧?

yj4018no1 | 园豆:181 (初学一级) | 2012-04-24 21:07

上述可以。

但我还有个追加问题,就是

Label lbl4 = (Label)e.Row.FindControl("Label4");
 string index = Convert.ToString(GridView1.DataKeys[e.Row.RowIndex].Value);

我想调用一个方法,

public static DataSet rbkxList(string rtid)
        {
            string sql_rbkx = "select count(r_status) from roominfo,roomtype where roominfo.rt_id=roomtype.rt_id and r_status='空闲' and roominfo.rt_id="+rtid;
            return DataAccess.ExecuteToDataSet(sql_rbkx);
        }

我预期的返回值是计算的count的值,请看下这个方法有没有错误?

还有就是,如何将该返回值,绑定给lbl4的text值?

请帮忙解决下。

支持(0) 反对(0) 语夫子 | 园豆:204 (菜鸟二级) | 2012-04-25 11:14

@语夫子: 将lab4隐藏,添加一个lab5的控件,然后

Label lbl5 = (Label)e.Row.FindControl("Label5");

lab5.text=“你想要赋得值”;

 

我预期的返回值是计算的count的值,请看下这个方法有没有错误?

string sql_rbkx = "select count(r_status) from roominfo,roomtype where roominfo.rt_id=roomtype.rt_id and r_status='空闲' and roominfo.rt_id="+rtid;
            return DataAccess.ExecuteToDataSet(sql_rbkx).table[0].rows[0][0].toString();

返回这个值就可以了

支持(0) 反对(0) kdkler | 园豆:154 (初学一级) | 2013-01-14 17:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册