DataGrid Data Source

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 30-May-2012 10:05:49   

LLBLGEN 3.5 .NET Framework 4.0 Self Servicing SQL Server 2005 C# Windows Application.

dgridsearchtitle.ReadOnly = true;
var Title = new TitleCollection();
Title.GetMulti(null);
dgridsearchtitle.DataSource = Title;

Above code displays all columns from table TITLE. I need two display only two columns. How can I do that ?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-May-2012 23:06:07   

You can hide the columns that you don't want from the Grid settings. Also you can Exclude Fields from being fetched.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 31-May-2012 06:23:49   

Walaa wrote:

You can hide the columns that you don't want from the Grid settings. Also you can Exclude Fields from being fetched.

dgridsearchtitle.ReadOnly = true;
            ExcludeIncludeFieldsList excludedFields = new ExcludeIncludeFieldsList();
            TitleCollection Title = new TitleCollection();
            excludedFields.Add(TitleFields.Flag);
            excludedFields.Add(TitleFields.Createddate);
            excludedFields.Add(TitleFields.Createduserid);
            excludedFields.Add(TitleFields.Modifieddate);
            excludedFields.Add(TitleFields.Modifieduserid);
            SortExpression sorter =
                new SortExpression(TitleFields.Description | SortOperator.Ascending);
            Title.GetMulti(null, 0, sorter, null, null, excludedFields, 0, 0);
            dgridsearchtitle.DataSource = Title;

Query executes correctly. But still the grid shows all the columns. I have not set any design time binding

Query: SELECT [LLBLGen].[dbo].[TITLE].[DESCRIPTION] AS [Description], [LLBLGen].[dbo].[TITLE].[TITLEID] AS [Titleid] FROM [LLBLGen].[dbo].[TITLE]   ORDER BY [LLBLGen].[dbo].[TITLE].[DESCRIPTION] ASC
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 31-May-2012 07:21:59   

The ExludeFields feature allows you to exclude irrelevant fields you won't use, but the entities still have all fields, it's just some fields will be empty (those you excluded). The grid, however doesn't know about this, the grid will just auto-populate all fields. You have to tell the grid what columns (fields) you want to show. The easiest way is to doing it at design-time. Example showing just two fields:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="orderDS" 
            DataKeyNames="OrderId" AllowPaging="True" PageSize="5">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="ShipAddress" HeaderText="ShipAddress" SortExpression="ShipAddress" />                
            </Columns>
        </asp:GridView>

For that I recommend you to read the LLBLGen docs section Databinding with ASP.Net. With LLBLGenProDataSource you can do almost any databound scenario with "0" lines of code.

I think you also could hide columns after the databind, something like:

dgridsearchtitle.DataSource = Title;
dgridsearchtitle.AutoGenerateColumns = true;
// hiding columns
// I'm not really sure about this code exactly, but you get the idea.
dgridsearchtitle.Columns[x].Hide();

David Elizondo | LLBLGen Support Team
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 31-May-2012 08:09:49   

daelmo wrote:

The ExludeFields feature allows you to exclude irrelevant fields you won't use, but the entities still have all fields, it's just some fields will be empty (those you excluded). The grid, however doesn't know about this, the grid will just auto-populate all fields. You have to tell the grid what columns (fields) you want to show. The easiest way is to doing it at design-time. Example showing just two fields:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="orderDS" 
            DataKeyNames="OrderId" AllowPaging="True" PageSize="5">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="ShipAddress" HeaderText="ShipAddress" SortExpression="ShipAddress" />                
            </Columns>
        </asp:GridView>

For that I recommend you to read the LLBLGen docs section Databinding with ASP.Net. With LLBLGenProDataSource you can do almost any databound scenario with "0" lines of code.

I think you also could hide columns after the databind, something like:

dgridsearchtitle.DataSource = Title;
dgridsearchtitle.AutoGenerateColumns = true;
// hiding columns
// I'm not really sure about this code exactly, but you get the idea.
dgridsearchtitle.Columns[x].Hide();

Ok. Thank you