views:

297

answers:

0

Hi,

I am using ComponentArt webDataGrid control , I can bind any EntityCollection to this control but i couldnt able to use with InnerJoined Entity Collections. My problem is ;

There is two table Products and Categories. I join Categories Table with Products Table.Then in my grid I wanna show Categories (Joined Table) in a Combobox included with my Grid. And show Master Table (Products) in Grid.There is no problem with Master Table's (Products) whole columns is visible at Grid but I cant see Joined Table (Categories)'s fields except CategoryID in comboBox.I can do that DataSet but Entityspaces.

Screenshot. alt text

Here is my Codes ;

private  ProductsCollection buildGrid()
{
    //string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
    //conStr += Server.MapPath("~/App_Data/demo.mdb");
    //System.Data.OleDb.OleDbConnection dbCon = new System.Data.OleDb.OleDbConnection(conStr);
    //dbCon.Open();

    //string sql;

    //sql = "SELECT * FROM Products";
    //System.Data.OleDb.OleDbDataAdapter daSrc = new System.Data.OleDb.OleDbDataAdapter(sql, dbCon);

    //DataTable oTable1 = new DataTable("Products");
    //daSrc.Fill(oTable1);

    //sql = "SELECT * FROM Categories";
    //daSrc = new System.Data.OleDb.OleDbDataAdapter(sql, dbCon);

    //DataTable oTable2 = new DataTable("Categories");
    //daSrc.Fill(oTable2);

    //DataSet dsSrc = new DataSet();
    //dsSrc.Tables.Add(oTable1);
    //dsSrc.Tables.Add(oTable2);

    //dsSrc.Relations.Add(dsSrc.Tables["Categories"].Columns["CategoryId"], dsSrc.Tables["Products"].Columns["CategoryId"]);
    ProductsQuery urun = new ProductsQuery("p");
    CategoriesQuery kategori = new CategoriesQuery("c");
    urun.Select(kategori.CategoryID, kategori.CategoryName,urun.LastOrderedOn, urun.ProductId, urun.ProductName, urun.QuantityPerUnit, urun.ReorderLevel, urun.UnitsInStock, urun.UnitsOnOrder,urun.UnitPrice );
    urun.InnerJoin(kategori).On(kategori.CategoryID == urun.CategoryID);
    ProductsCollection procoll = new ProductsCollection();

    procoll.Load(urun);

    return procoll;
}

private void Page_Load(object sender, System.EventArgs e)
{

    if (!Page.IsPostBack)
    {
       ProductsCollection dsSrc = buildGrid();
        Grid1.DataSource = dsSrc;
        Grid1.DataBind();
        ComponentArt.Web.UI.ComboBox comboBox = (ComponentArt.Web.UI.ComboBox)Grid1.FindControl("ComboBox1");
        comboBox.DataSource = dsSrc;
        //comboBox.DataMember = "Categories";
        comboBox.DataTextField = "CategoryName";
        comboBox.DataValueField = "CategoryId";
        comboBox.DataBind();
        //GridView1.DataSource = dsSrc;
        //GridView1.DataBind();

    }
    else
    {
        lblFeedback.Text = "<b>Actions Performed:</b><br/>";
    }
}

DEFAULT.ASPX

function Grid1_onItemBeforeInsert(sender, eventArgs) { if (document.getElementById('chkConfirmInsert').checked) if (!confirm("Insert record?")) eventArgs.set_cancel(true); } function Grid1_onItemBeforeUpdate(sender, eventArgs) { if (document.getElementById('chkConfirmUpdate').checked) if (!confirm("Update record?")) eventArgs.set_cancel(true); } function Grid1_onItemBeforeDelete(sender, eventArgs) { if (document.getElementById('chkConfirmDelete').checked) if (!confirm("Delete record?")) eventArgs.set_cancel(true); } function Grid1_onCallbackError(sender, eventArgs) { if (confirm('Invalid data has been entered. View details?')) alert(eventArgs.get_errorMessage()); Grid1.page(0); } function getCategory() { // because we need to store both category ID and Text, we return them as a pair var item = ComboBox1.getSelectedItem(); return [item.get_value(), item.get_text()]; } function setCategory(DataItem) { ComboBox1.element.style.visibility = 'visible'; ComboBox1.beginUpdate(); for (var i = 0; i

<div>
<ComponentArt:DataGrid id="Grid1"
    AutoTheming="true"
    AutoCallBackOnInsert="true"
    AutoCallBackOnUpdate="true"
    AutoCallBackOnDelete="true"
    EditOnClickSelectedItem="false"
    CallbackReloadTemplates="false"
    AllowEditing="true"
    ShowHeader="False"
    KeyboardEnabled="false"
    RunningMode="Callback"
    PagerStyle="Numbered"
    PageSize="15"
    ImagesBaseUrl="images/"
    width="730" Height="350"
    runat="server">
    <ClientEvents>
      <CallbackError EventHandler="Grid1_onCallbackError" />
      <ItemBeforeInsert EventHandler="Grid1_onItemBeforeInsert" />
      <ItemBeforeUpdate EventHandler="Grid1_onItemBeforeUpdate" />
      <ItemBeforeDelete EventHandler="Grid1_onItemBeforeDelete" />
    </ClientEvents>
    <Levels>
      <ComponentArt:GridLevel
        DataKeyField="ProductId"
        ShowTableHeading="false"
        ShowSelectorCells="true"
        SelectorCellWidth="18"
        SelectorImageUrl="selector.gif"
        SelectorImageWidth="17"
        SelectorImageHeight="15"
        EditCommandClientTemplateId="EditCommandTemplate"
        InsertCommandClientTemplateId="InsertCommandTemplate"
        >
        <Columns>
          <ComponentArt:GridColumn AllowEditing="false" DataField="ProductId" Visible="false"/>
          <ComponentArt:GridColumn DataField="CategoryId" HeadingText="Category" ForeignTable="Categories" ForeignDataKeyField="CategoryID" ForeignDisplayField="CategoryName" EditControlType="Custom" EditCellServerTemplateId="ComboBoxTemplate" CustomEditSetExpression="setCategory(DataItem)" CustomEditGetExpression="getCategory()" Width="140" />
          <ComponentArt:GridColumn DataField="ProductName"/>
          <ComponentArt:GridColumn DataField="LastOrderedOn" Width="200" FormatString="MM/dd/yyyy" EditControlType="Custom" EditCellServerTemplateId="PickerTemplate" CustomEditSetExpression="setValue(DataItem)" CustomEditGetExpression="getValue()" />
          <ComponentArt:GridColumn DataField="UnitPrice" />
          <ComponentArt:GridColumn DataField="UnitsInStock" Width="50" />
          <ComponentArt:GridColumn AllowSorting="false" HeadingText="Edit Command" DataCellClientTemplateId="EditTemplate" EditControlType="EditCommand" Width="100" Align="Center" />
        </Columns>
      </ComponentArt:GridLevel>
    </Levels>
    <ClientTemplates>
      <ComponentArt:ClientTemplate Id="EditTemplate">
        <a href="javascript:editGrid('## DataItem.ClientId ##');">Edit</a> | <a href="javascript:deleteRow('## DataItem.ClientId ##')">Delete</a>
      </ComponentArt:ClientTemplate>
      <ComponentArt:ClientTemplate Id="EditCommandTemplate">
        <a href="javascript:editRow();">Update</a> | <a href="javascript:Grid1.EditCancel();">Cancel</a>
      </ComponentArt:ClientTemplate>
      <ComponentArt:ClientTemplate Id="InsertCommandTemplate">
        <a href="javascript:insertRow();">Insert</a> | <a href="javascript:Grid1.EditCancel();">Cancel</a>
      </ComponentArt:ClientTemplate>          
    </ClientTemplates>
    <ServerTemplates>
      <ComponentArt:GridServerTemplate Id="ComboBoxTemplate">
        <Template>
<ComponentArt:ComboBox id="ComboBox1" runat="server"
  CssClass="comboBox" TextBoxEnabled="false"
  HoverCssClass="comboBoxHover" SelectedIndex="4"
  FocusedCssClass="comboBoxHover"
  TextBoxCssClass="comboTextBox"
  DropDownCssClass="comboDropDown"
  ItemCssClass="comboItem"
  ItemHoverCssClass="comboItemHover"
  SelectedItemCssClass="comboItemHover"
  DropHoverImageUrl="images/drop_hover.gif"
  DropImageUrl="images/drop.gif"
  Width="120" />
        </Template>
      </ComponentArt:GridServerTemplate>
      <ComponentArt:GridServerTemplate Id="PickerTemplate">
        <Template>

   <table cellspacing="0" cellpadding="0" border="0">
    <tr>
      <td onmouseup="Button_OnMouseUp()"><ComponentArt:Calendar id="Picker1"
          runat="server"
          PickerFormat="Custom"
          PickerCustomFormat="MMMM d yyyy"
          ControlType="Picker"
          SelectedDate="2005-9-13"
          ClientSideOnSelectionChanged="Picker1_OnDateChange"
          PickerCssClass="picker" /></td>
      <td style="font-size:10px;">&nbsp;</td>
      <td><img id="calendar_from_button" alt="" onclick="Button_OnClick(this)" onmouseup="Button_OnMouseUp()" class="calendar_button" src="images/btn_calendar.gif" /></td>
    </tr>
    </table>

    <ComponentArt:Calendar runat="server"
          id="Calendar1"
          AllowMultipleSelection="false"
          AllowWeekSelection="false"
          AllowMonthSelection="false"
          ControlType="Calendar"
          PopUp="Custom"
          PopUpExpandControlId="calendar_from_button"
          CalendarTitleCssClass="title"
          SelectedDate="2005-9-13"
          VisibleDate="2005-9-13"
          ClientSideOnSelectionChanged="Calendar1_OnChange"
          DayHeaderCssClass="dayheader"
          DayCssClass="day"
          DayHoverCssClass="dayhover"
          OtherMonthDayCssClass="othermonthday"
          SelectedDayCssClass="selectedday"
          CalendarCssClass="calendar"
          NextPrevCssClass="nextprev"
          MonthCssClass="month"
          SwapSlide="Linear"
          SwapDuration="300"
          DayNameFormat="FirstTwoLetters"
          PrevImageUrl="images/cal_prevMonth.gif"
          NextImageUrl="images/cal_nextMonth.gif"
            />

        </Template>
      </ComponentArt:GridServerTemplate>
    </ServerTemplates>
  </ComponentArt:DataGrid>

  <br />
  <table width="730" cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td width="270" valign="top">
      <span class="hint">Insert, update, and delete any number of records. All changes are applied immediately through callbacks. </span><br><br>
      <asp:CheckBox id="chkConfirmInsert" Text="Confirm Before Insert" Checked="false" runat="server" /> <br>
      <asp:CheckBox id="chkConfirmUpdate" Text="Confirm Before Update" Checked="false" runat="server" /> <br>
      <asp:CheckBox id="chkConfirmDelete" Text="Confirm Before Delete" Checked="false" runat="server" /> <br><br>
    </td>
    <td valign="top">
      <asp:Label id="lblFeedback" runat="server" />
    <td>
    <td align="right" valign="top"><input type="button" onclick="Grid1.Table.AddRow()" value="Add row" /></td>
  </tr>
  </table>

</div>
</div>