日期:2014-05-18  浏览次数:20444 次

憋了三天没做出来~gridview模板列数据绑定问题:在线等
gridview中模板列中默认绑定的显示的数据是“活动”的Id,但是我要通过这个Id去另一个“活动”表去查找对应的“活动名称”显示在gridview中模板列中。有没有人做过啊?


------解决方案--------------------
你绑定的时候<%# getname(id) %>执行后台函数
返回名称不就行了吗
------解决方案--------------------
1、先用存储过程取出你要的所有数据。
2、写个方法把数据取出来给dt.
3、把dt=Gridview.DataSource.
C# code
  private void GetAllComInformation()
        {
            DataTable dt = new DataTable();
            dt = dw.PreventGetAll();
            GridView_Prevent.DataSource = dt;
            GridView_Prevent.DataBind();
        }

------解决方案--------------------
rowdataBound 事件中
//dt 为返回的datatable,即包含 “活动”的Id 和名称的那张表
lable lbl = (lable)e.rows.cells["对应列名"].controls[0];
lbl.text = dt.rows[0]["活动列名"].toString();

------解决方案--------------------
private void GetAllComInformation()
改成
protected void GetAllComInformation()

或者
public void GetAllComInformation()


不过,楼主这种写法应该会报错吧