Click here to Skip to main content
15,911,786 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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...

XML
<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>


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
Posted

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:
C#
// 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.
 
Share this answer
 
Check This

May this help you
Thank You
@ChetanV@
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900