﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - WebGrid Enterprise - Bind 2 WebGrids to Dataset</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Bind-2-WebGrids-to-Dataset/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>Bind 2 WebGrids to Dataset</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Bind-2-WebGrids-to-Dataset/</link><pubDate>Tue, 15 Sep 2009 16:15:01 GMT</pubDate><dc:creator>Michael</dc:creator><description>&lt;p&gt;Hi James&lt;/p&gt;
&lt;p&gt;Sorry, I was confused about &lt;em&gt;&lt;strong&gt;DataMember="DataSetA".&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;At the second reading I've noticed that you mean the DataTable...&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Here is the complete and functional code:&lt;/p&gt;&lt;pre&gt;private DataSet ds;

protected void Page_Load(object sender, EventArgs e)
{
    ds = GetData();
}

protected void grd1_PrepareDataBinding(object sender, DataSourceEventArgs e)
{
    if (!Page.IsPostBack)
    {
        grd1.ClearCachedDataSource();
        grd1.RetrieveStructure();
    }
}

protected void grd1_InitializeDataSource(object sender, DataSourceEventArgs e)
{
    grd1.DataMember = "&amp;lt;DataTable1&amp;gt;";
    grd1.RootTable.DataMember = "&amp;lt;DataTable1&amp;gt;";
    e.DataSource = ds;
}

protected void grd2_PrepareDataBinding(object sender, DataSourceEventArgs e)
{
    if (!Page.IsPostBack)
    {
        grd2.ClearCachedDataSource();
        grd2.RetrieveStructure();
    }
}

protected void grd2_InitializeDataSource(object sender, DataSourceEventArgs e)
{
    grd2.DataMember = "&amp;lt;DataTable2&amp;gt;";
    grd2.RootTable.DataMember = "&amp;lt;DataTable2&amp;gt;";
    e.DataSource = ds;
}&lt;/pre&gt;

&lt;p&gt;Thank you, James!&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Michael&lt;/p&gt;</description></item><item><title>Bind 2 WebGrids to Dataset</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Bind-2-WebGrids-to-Dataset/</link><pubDate>Tue, 15 Sep 2009 13:01:18 GMT</pubDate><dc:creator>james</dc:creator><description>&lt;p&gt;Michael,&lt;/p&gt;&lt;p&gt;WebGrid will use the first data table in the DataSet only when the DataMember is not specified.&lt;/p&gt;
&lt;p&gt;So if you have 3 data tables in your DataSet, you can have WebGrid to display one of the data tables by specifying the &lt;b&gt;DataMember&lt;/b&gt; in the &lt;b&gt;WebGrid&lt;/b&gt; and &lt;b&gt;RootTable&lt;/b&gt; object, which is shown in my previous sample code.&lt;/p&gt;
&lt;p&gt;For your convenience, let me paste the code where you can specify the data table to be displayed.&lt;/p&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="color: rgb(63, 63, 63); font-family: 'segoe ui', arial, verdana, tahoma; font-size: 12px; line-height: 18px; "&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre style="font-family: 'courier new', tahoma; background-color: rgb(255, 252, 225); font-size: 9pt; white-space: pre-wrap; word-wrap: break-word; "&gt;&amp;lt;ISWebGrid:WebGrid ID="grdPC" runat="server" &lt;b style="font-family: 'segoe ui', arial, verdana, tahoma; "&gt;DataMember&lt;/b&gt;="DataSetA" ...&amp;gt;
     &amp;lt;RootTable &lt;b style="font-family: 'segoe ui', arial, verdana, tahoma; "&gt;DataMember&lt;/b&gt;="DataSetA" ...&amp;gt;
      ...
     &amp;lt;/RootTable&amp;gt;
&amp;lt;/ISWebGrid:WebGrid&amp;gt;&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Hope this helps,&lt;br /&gt;James.&lt;/p&gt;</description></item><item><title>Bind 2 WebGrids to Dataset</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Bind-2-WebGrids-to-Dataset/</link><pubDate>Tue, 15 Sep 2009 11:49:08 GMT</pubDate><dc:creator>Michael</dc:creator><description>&lt;p&gt;Hi James&lt;/p&gt;
&lt;p&gt;I can't follow your explanation.&lt;/p&gt;
&lt;p&gt;In your Example, you bind always to Dataset, but where have I choose the Data Table?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I have also problems with following Scenario:&lt;/p&gt;
&lt;p&gt;How can I change DataTable, if I have a Dataset with 3 Tables? The WebGrid shows always Data from the first added Table (to Dataset).&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Michael&lt;/p&gt;</description></item><item><title>Bind 2 WebGrids to Dataset</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Bind-2-WebGrids-to-Dataset/</link><pubDate>Fri, 28 Aug 2009 05:13:10 GMT</pubDate><dc:creator>james</dc:creator><description>&lt;p&gt;Michael,&lt;/p&gt;&lt;p&gt;Yes, you can easily bind two WebGrids into a dataset. Make sure the Grid's &lt;b&gt;DataMember&lt;/b&gt; and the RootTable's &lt;b&gt;DataMember&lt;/b&gt; is assigned to the target datatable's name in the Grid definition (aspx). Then, your &lt;b&gt;InitializeDataSource&lt;/b&gt; should be pointed to a dataset, not to a datatable.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&amp;lt;ISWebGrid:WebGrid ID="grdPC" runat="server" &lt;b&gt;DataMember&lt;/b&gt;="DataSetA" ...&amp;gt;
     &amp;lt;RootTable &lt;b&gt;DataMember&lt;/b&gt;="DataSetA" ...&amp;gt;
      ...
     &amp;lt;/RootTable&amp;gt;
&amp;lt;/ISWebGrid:WebGrid&amp;gt;&lt;/pre&gt;
&lt;p&gt;Then for InitializeDataSource:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre&gt;protected void grdPC_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
{
    e.DataSource = ds;
}
&lt;/pre&gt;
&lt;p&gt;This way, WebGrid will be able to dispatch the target data table from the dataset, based on the given data member that bound to the WebGrid's table.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Let me know how it goes in your end.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;James.&lt;/p&gt;</description></item><item><title>Bind 2 WebGrids to Dataset</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Bind-2-WebGrids-to-Dataset/</link><pubDate>Fri, 28 Aug 2009 02:29:32 GMT</pubDate><dc:creator>Michael</dc:creator><description>&lt;p&gt;Here is the original code.&lt;/p&gt;
&lt;p&gt;Let me explain:&lt;/p&gt;
&lt;p&gt;I have a table with Productionlines and a table with Computers. Enduser can define, which Computer works on which Productionline (Multiple choice is possible). Userinputs are stored in third table called by ComputerLine. On this way, I have two 1:n relationships (see DB-Diagram in attached file).&lt;/p&gt;
&lt;p&gt;On Page I want display Productionlines and Computers in an own table. Enduser should be able to link the records in these tables. I would prefer to Drag and Drop, but I have also trouble (see &lt;a href="http://www.intersoftpt.com/Community/WebDesktop/DragDrop-WebGrid-to-WebTreeview-using-WebPaneManager/" target="_blank"&gt;DragDrop (WebGrid to WebTreeview) using WebPaneManager&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;The easiest way to solve this issue: I load tables in separate Datasets, but I'm not happy with this idea...&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #ff0000"&gt;How would you implement this scenario?&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;private DataSet ds;

protected void Page_Load(object sender, EventArgs e)
{
    ds = GetData();
}

protected void grdLine_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
{
    e.DataSource = ds.Tables["Line"];
}

protected void grdLine_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
{
    if (!Page.IsPostBack)
    {
        grdLine.RetrieveStructure();
    }
}

protected void grdPC_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
{
    e.DataSource = ds.Tables["Computer"];
}

protected void grdPC_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
{
    if (!Page.IsPostBack)
    {
        grdPC.RetrieveStructure();
    }
}

protected void grdComputerLine_InitializeDataSource(object sender, DataSourceEventArgs e)
{
    e.DataSource = ds.Tables["ComputerLine"];
}

protected void grdComputerLine_PrepareDataBinding(object sender, DataSourceEventArgs e)
{
    if (!Page.IsPostBack)
    {
        grdComputerLine.RetrieveStructure();

        WebGridColumn colID = grdComputerLine.RootTable.Columns[0];
        colID.Width = Unit.Pixel(100);
        colID.ColumnType = ColumnType.Text;

        WebGridColumn colLineID = grdComputerLine.RootTable.Columns[1];
        colLineID.Width = Unit.Pixel(100);
        colLineID.ColumnType = ColumnType.Text;
    }
}

public DataSet GetData()
{
    // Connection
    SqlConnection cn = new SqlConnection();
    cn.ConnectionString = @"xxx";
    cn.Open();

    using (cn)
    {
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = cn;
        cmd.CommandText = "SELECT ID,Name FROM Production.Line; " &amp;#43;
            "SELECT ID,Name FROM Production.Computer; " &amp;#43;
            "SELECT ComputerID,LineID FROM Maintenance.ComputerLine";

        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        da.TableMappings.Add("Table", "Line");
        da.TableMappings.Add("Table1", "Computer");
        da.TableMappings.Add("Table2", "ComputerLine");

        DataSet ds = new DataSet();
        da.Fill(ds);
        da.FillSchema(ds, SchemaType.Source);

        DataRelation rel;
        rel = new DataRelation("relLineComputerLine",
            ds.Tables["Line"].Columns["ID"],
            ds.Tables["ComputerLine"].Columns["LineID"]);
        ds.Relations.Add(rel);

        rel = new DataRelation("relComputerComputerLine",
            ds.Tables["Computer"].Columns["ID"],
            ds.Tables["ComputerLine"].Columns["ComputerID"]);
        ds.Relations.Add(rel);

        return ds;
    }&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;</description></item><item><title>Bind 2 WebGrids to Dataset</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Bind-2-WebGrids-to-Dataset/</link><pubDate>Wed, 26 Aug 2009 09:48:01 GMT</pubDate><dc:creator>uk.codeguru@googlemail.com</dc:creator><description>&lt;p&gt;Looks like you missed out some of the code. Could you paste the complete code.  &lt;/p&gt;
&lt;p&gt;From your error description it looks like, may be you have set the same DataKeyField IDTableA for both the grids and this might be creating a problem as the other grid does not have this column in its datasource.&lt;/p&gt;</description></item><item><title>Bind 2 WebGrids to Dataset</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Bind-2-WebGrids-to-Dataset/</link><pubDate>Tue, 25 Aug 2009 04:27:29 GMT</pubDate><dc:creator>Michael</dc:creator><description>&lt;p&gt;Hi &lt;/p&gt;
&lt;p&gt;I have a Dataset with 2 DataTables (Table A and Table B).&lt;/p&gt;
&lt;p&gt;On the Page they are 2 WebGrids (WebGrid A and WebGrid B)&lt;/p&gt;
&lt;p&gt;Now, I want bind WebGrid A to Table A and WebGrid B to Table B.&lt;/p&gt;
&lt;p&gt;How can I do this?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I have written the following Code:&lt;/p&gt;
&lt;p&gt;On Page_Load I fill the Dataset with 2 Tables &lt;/p&gt;&lt;pre&gt;        protected void Page_Load(object sender, EventArgs e)
        {
            ds = GetData();
        }&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;GetData() has 2 Select-Statement: &lt;/p&gt;
&lt;p&gt;SELECT ID AS IDTableA FROM TableA&lt;/p&gt;
&lt;p&gt;SELECT ID AS IDTableB FROM TableB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;On InitializeDatasSource (similar for Table B):&lt;/p&gt;&lt;pre&gt;        protected void WebGridA_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
        {
            e.DataSource = ds.Tables["TableA"];
        }&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;On PrepareDataBinding (similar for Table B):&lt;/p&gt;&lt;pre&gt;        protected void WebGridA_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
        {
            if (!Page.IsPostBack)
            {
                WebGridA.RetrieveStructure();
            }

        }

&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If I run the project, I get an exception "Can't find DataColumn with name 'IDTableA' in the specified datasource"&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I have also tried to set DataMember = TableA/TableB in PrepareDataBinding-Event. Then both WebGrid have the same Data!&lt;/p&gt;
&lt;p&gt;How can I bind 2 WebGrids to Dataset?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks for help.&lt;/p&gt;
&lt;p&gt;Michael&lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>