User Profile & Activity

Michael Giger Member
Page
of 8
Posted: August 28, 2009 2:29 AM

Here is the original code.

Let me explain:

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).

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 DragDrop (WebGrid to WebTreeview) using WebPaneManager)

The easiest way to solve this issue: I load tables in separate Datasets, but I'm not happy with this idea...

How would you implement this scenario?

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; " +
            "SELECT ID,Name FROM Production.Computer; " +
            "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;
    }

Hi James

Thanks for your answer!

I have tested your code, but it doesn't works.   The OnDragQuery Event isn't fired.

It's not enough to change effect, because I can also add Clildnodes only!

Regards

Michael

Thanks for your answer.

What did you mean with near future?

- WebUI 2009 R2?

- Next Year?

- Later?

Posted: August 26, 2009 10:31 AM

I bound a DataSet on InitalizeDataSource-Event to WebGrid.

Posted: August 26, 2009 8:27 AM

Hi Glenn

I have a table with 2 Foreignkey-Columns, which together define the Primarykey of this table.

The Columntypes are GUID. Small Batch Update is active.

On WebGrid1_PrepareDataBinding-Event I call RetrieveStructure().

 

If I add the following 2 Records, I get a Message from Website: The pending changes already contain a record with key ''

First Record:

00000000-0000-0000-0000-000000000001 and 10000000-0000-0000-0000-000000000000

Second Record:

00000000-0000-0000-0000-000000000002 and 10000000-0000-0000-0000-000000000000

 

On Debugmode I have seen, both columns are type of System.Guid and DataKeyField is not set.

 

How can I solve this problem?

Hi Dicky

Thank you for tip!

Where can I find a list of all menu items name?
Michael

Hi Memo

You can use the client-side-event OnRowContextMenu.

You just need to find out how the menu is called.
Here is an example to hide the Help menu:
 
 
  function grdPL_OnRowContextMenu(controlId, rowType, rowElement, menuObject)
  {
      var i;
      for (i = 0; i < menuObject.Items.length; i  ) {
          if (menuObject.Items[i] != null) {
              if (menuObject.Items[i].Name == "mnuHelp") {
                  menuObject.Items[i - 1].Hide();
                  menuObject.Items[i].Hide();
              }
          }
      }
   return true;
  }

Hope it helps.

Michael

All times are GMT -5. The time now is 8:57 AM.
Previous Next