View Full Version : [CLOSED] LinqDataSource combining columns/aliasing

Nov 13, 2014, 2:18 PM
I would like define a column value based on two other columns. I could perform the following option:

<asp:LinqDataSource ID="LDS" runat="server" ContextTypeName="MyContext"
Select="new #RequestCatId, RequestCatAbbr, RequestCatAbbr + " (" + IsActive + ")" as RequestCatAbbrNew, IsActive#
OrderBy="IsActive desc, RequestCatAbbr" />

This would provide results like:

Baseline (true)
Research (true)
Archived Documents (false)

What I really want is:?

Archived Documents (Inactive)

In TSQL the query would look like:

select RequestCatId, RequestCatAbbr,
RequestCatAbbrNew = CASE IsActive when 0 then RequestCatAbbr + ' (Inactive)' when 1 then RequestCatAbbr END,
from Categories
order by IsActive desc, RequestCatAbbr

I could also perform a Union in SQL:

select RequestCatId, RequestCatAbbr, RequestCatAbbr as RequestCatAbbrNew, IsActive
from Categories
where IsActive = 1
select RequestCatId, RequestCatAbbr, RequestCatAbbr + ' (Inactive)' as RequestCatAbbrNew, IsActive
from Categories
where IsActive = 0
order by IsActive desc, RequestCatAbbr

The question above eventually gets me to the following design. I have a GridPanel that shows the RequestCatAbbr dataIndex. I have added a ListFilter on the dataIndex RequestCatAbbr. I would like the ListFilter labels (LabelField) to be readable and thus use the RequestCatAbbrNew while the IDField will be the raw data RequestCatAbbr.

I have the ListFilter set up correctly. I just can't build the string that I want to use.

Any thoughts?

Nov 14, 2014, 5:33 AM
Hi Chris,

It looks I don't understand the requirement clearly. How does the serialized data look finally? I mean a JSON object that goes to the Store.

Ideally, could you provide a test case, please? Without the dependance on LinqDataSource, just with some test data that mimics the real data.

Nov 14, 2014, 2:46 PM
I guess I was trying to make this harder then it needed to be. I was initially hoping to populate the CategoryStore from the clientside via the LinqDataSource. But I guess I will just do it during PageLoad on the server side and build the data myself after retrieving the rows from the database.

Here is what I want to see. The ListFilter LabelField is built using the Cat and IsActive attributes while the IdField is the Cat attribute. One wrinkle is that if the IsActive is true the LabelField is just the Cat.

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
if (!X.IsAjaxRequest)
this.GridStore.DataSource = new object[]
new object[] { 1, "Baseline", "Training Guide"},
new object[] { 2, "Reference", "How to ..."},
new object[] { 3, "Archive", "Training Guide (1983)"},


List<object> data = new List<object>
new { Cat = "Baseline", IsActive = true, CatCombined = "Baseline" },
new { Cat = "Reference", IsActive = true, CatCombined = "Reference" },
new { Cat = "Archive", IsActive = false, CatCombined = "Archive (Inactive)" }

this.CategoryStore.DataSource = data;
<head runat="server">
<title>ListFiler Example</title>
<ext:ResourceManager runat="server" />
<ext:GridPanel runat="server">
<ext:Store ID="CategoryStore" runat="server">
<ext:Model runat="server" IDProperty="Cat">
<ext:ModelField Name="id" Mapping="Cat" Type="String" />
<ext:ModelField Name="IsActive" Type="Boolean" />
<ext:ModelField Name="CatCombined" Type="String" />
<ext:Store ID="GridStore" runat="server">
<ext:Model runat="server">
<ext:ModelField Name="Id" />
<ext:ModelField Name="Category" Type="String" />
<ext:ModelField Name="Title" Type="String" />
<ColumnModel runat="server">
<ext:Column runat="server" Text="Id" DataIndex="Id" Width="50" />
<ext:Column runat="server" Text="Category" DataIndex="Category" Width="120" />
<ext:Column runat="server" Text="Title" DataIndex="Title" Flex="1" />
<ext:RowSelectionModel runat="server" Mode="Single" />
<ext:GridFilters ID="GridFilters" runat="server" Local="true">
<ext:ListFilter DataIndex="Category" StoreID="CategoryStore" LabelField="CatCombined" IDField="id" />

If you don't have any other thoughts, you can close the thread.

Nov 14, 2014, 5:43 PM
Please close the thread. Before posting I should go home, relax and think about what I really want to do. Not sure why my brain wanted to do everything on the markup side.

So in my Page_Load I populate the CategoryStore from the database by the following code:

CRTSObjsDataContext db = new CRTSObjsDataContext();
List<CrtsRequestCategory> categories = db.CrtsRequestCategories
.OrderByDescending(p => p.IsActive)
.ThenBy(p => p.RequestCatAbbr)

List<object> data = new List<object>();

foreach (CrtsRequestCategory category in categories)
object storeData = new
Cat = category.RequestCatAbbr,
IsActive = category.IsActive,
CatCombined = category.IsActive ? category.RequestCatAbbr : category.RequestCatAbbr + " (Inactive)"

CategoryStore.DataSource = data;