日期:2014-05-19  浏览次数:20477 次

|M| 更以前别的人代理,我在aspx改,有个地方让高人来指点一下 谢谢
如有一个DataGrid绑定了以下表和字段
Product
id   product   from
1     apple       china
2     banana     china
3     orange     USA

然后现在又多了一个表
Price  
id     ProductID   Price   SalePrice   begindate     enddate
1       1                   10         15                 2007-04-20   2007-05-20

现在要求把Price这个表的信息也绑定到product里面
本来最简单的办法是product   price关联查询绑定
但现在要求是不更改原来的aspx.cs文件
所以我就在前台
<%@   Import   Namespace= 'com.Price '   %>     //导入我的price DLL
然后给DataGrid添加四列,分别对应以下
Price.GetDetail(Eval( "ProductID ")).Price
Price.GetDetail(Eval( "ProductID ")).SalePrice
Price.GetDetail(Eval( "ProductID ")).BeginDate
Price.GetDetail(Eval( "ProductID ")).EndDate
这样可以做到,但是这里要再对数据库进行四次查询
但查询出来的记录其实是一样的
所以我想问我查询出来的记录如何赋值给DataGrid里面行的N个控件的值

谢谢

------解决方案--------------------

------解决方案--------------------
Price.GetDetail(Eval( "ProductID ")).Price
Price.GetDetail(Eval( "ProductID ")).SalePrice
Price.GetDetail(Eval( "ProductID ")).BeginDate
Price.GetDetail(Eval( "ProductID ")).EndDate
四次肯定是要的

------解决方案--------------------
摸板可以吧
------解决方案--------------------
我来写写看
------解决方案--------------------
吃饭先
------解决方案--------------------
加入一个模板列,里面放一个表格,表格包含这4个数据,可以一次输出
------解决方案--------------------
<asp.TemplateColumn ....>
<ItemTemplate>
.....
</ItemTemplate>
</asp.TemplateColumn>


<%# DataBinder.Eval(Container, "DataItem.Price ")&
------解决方案--------------------
<script language= "C# " runat= "server "> protected System.Data.DataSet ds = null; string GetDetail(string sId) { if (ds == null) { //查询 } 取出相应的数据,显示. } </script>
------解决方案--------------------
学习..
------解决方案--------------------
<script language= "C# " runat=server>
public object objPriceInfo = null;
</script>
放到你的grid前面
Price.GetDetail(Eval( "ProductID ")) 这个函数你应该是返回的Price对象.

<%# objPriceInfo = Price.GetDetail(Eval( "ProductID ")) %>
<asp:Lable id=Price Text= ' <%# objPriceInfo.Price %> ' runat= 'server '/>
<asp:Lable id=SalePrice Text= ' <%# objPriceInfo.SalePrice %> ' runat= 'server '/>
<asp:Lable id=BeginDate Text= ' <%# objPriceInfo.BeginDate %> ' runat= 'server '/>
<asp:Lable id=EndDate Text= ' <%# objPriceInfo.EndDate %> ' runat= 'server '/>




<%# objPriceInfo = Price.GetDetail(Eval( "ProductID ")) %>