我可以使用两个或多个数据集数据绑定到一个数据列表中吗? [英] can i bind in one datalist using two or more dataset data ?

查看:177
本文介绍了我可以使用两个或多个数据集数据绑定到一个数据列表中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用两个数据集来绑定数据列表中的数据.

有可能吗?

两个数据集之一包含一些数据,
另一个包含表的剩余数据...

i want to bind data in datalist using two dataset.

is it possible ???

one of two dataset contain some data,
another one consist remainiing data of table...

<asp:DataList ID="DataList1" runat="server" RepeatColumns="4">
       <ItemTemplate>
       <table border="1" style="margin-left:10px;margin-bottom:10px;">
       <tr>
       <td><%# DataBinder.Eval(Container.DataItem,"pid") %></td>
       </tr>
       <tr>
       <td><%# DataBinder.Eval(Container.DataItem,"pname") %></td>
       </tr>
       <tr>
       <td><%# DataBinder.Eval(Container.DataItem,"pprice") %></td>
       </tr>
       <tr>
       <td><%# DataBinder.Eval(Container.DataItem,"Stime") %></td>
       </tr>
       <tr>
       <td><%# DataBinder.Eval(Container.DataItem,"Ctime") %></td>
       </tr>
       </table>
       </ItemTemplate>
       </asp:DataList>



在此代码中

我想从一个数据集中绑定pid,pname和pprice,并且
剩余的Stime和Ctime,我想使用另一个数据集来绑定这两个,所以我该如何解决....

请帮忙.....
感谢



in this code

i want to bind pid, pname and pprice from one dataset and
remaining Stime and Ctime , i want to bind this two using another dataset so how can i solve....

please help.....
thanks

推荐答案


您可以合并DataTables或DataSet以获得单个DataSource,因为不可能将两个不同的数据源绑定到单个控件.看一下这个样本,它将阐明解决方案:
Hi,
You can merge your DataTables or DataSets in order to have a single DataSource as it is not possible to bind two different data sources to a single control. Take a look at this sample which will clarify the solution:
// This is table one. 
    DataTable t1 = new DataTable(); 
    t1.Columns.Add("key1"); 
    t1.Columns.Add("c1"); 
    t1.PrimaryKey = new[]{t1.Columns["key1"]}; 
    t1.Rows.Add(1, "data1"); 


    // This is table two. 
    DataTable t2 = new DataTable(); 
    t2.Columns.Add("key1"); 
    t2.Columns.Add("c2"); 
    t2.PrimaryKey = new[] { t2.Columns["key1"] }; 
    t2.Rows.Add(1, "data2"); 


    // Combine table one with table two. 
    t1.Merge(t2, false, MissingSchemaAction.Add); 


    // Read "c2" field from table one 
    Response.Write(t1.Rows[0]["c2"].ToString()); 



希望对您有帮助,
干杯.



I hope it helps,
Cheers.


选中此

可能对您有帮助
谢谢
@ChetanV @
Check This

May this help you
Thank You
@ChetanV@


这篇关于我可以使用两个或多个数据集数据绑定到一个数据列表中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆