C# - Dynamic Columns With LinqDataSource?

Aug 24, 2010

Im using LinqDataSource like that:

<asp:LinqDataSource ID="LinqDataSource3" runat="server" OnSelecting="LinqDataSource3_OnSelecting">
</asp:LinqDataSource>
And I have ASPxGridView
<dxwgv:ASPxGridView ID="ASPxGridView2" ClientInstanceName="ASPxGridView2Client"
runat="server" AutoGenerateColumns="False"
DataSourceID="LinqDataSource3">
</dxwgv:ASPxGridView>

In this way Im able to add columns dynamically while handling onSelecting event:

protected void LinqDataSource3_OnSelecting(object sender, LinqDataSourceSelectEventArgs e)
{
MyModelDataContext context = new MyModelDataContext();
ASPxGridView grid = ASPxPageControl1.TabPages[3].FindControl("ASPxGridView2") as ASPxGridView;
if(grid.Columns.Count == 0){
GridViewDataTextColumn txtColumn1 = new GridViewDataTextColumn();
GridViewDataTextColumn txtColumn2 = new GridViewDataTextColumn();
txtColumn1.FieldName = "UserId";
txtColumn2.FieldName = "FirstName";
grid.Columns.Add(txtColumn1);
grid.Columns.Add(txtColumn2);
}
e.Result = from u in context.Users select new { UserId = u.UserId, FirstName = u.FirstName };
}

It is all made simply to test cause my idea is to have solution that makes it possible to use inqDataSource as a datasource for de ASPxGridView but join 2 or 3 tables and show results in this grid.

What I want to ask is if its good solution or is there any other better way to present some views made from couple of tables by join?

Second question is that I have Users and Group and I would like to have one table in which I would have two columns Name and Type For groups type would by group and for users type would be user. I dont have such a table in my database Is it possible to create specific class. Create List of objects of that class and fill it using linq query and the use it as linq data source for that grid ?

clas would be:

pseudocode:

Class MyClass {
string Type;
string Name;
}

or is there any other way to create such a table ?

View 1 Replies


Similar Messages:

C# - Getting Xml Columns From LinqDataSource To Appear In A GridView?

Jul 25, 2010

I have a LinqDataSource and a GridView displaying a table. Columns of type xml don't show up. I'd like them to show up something like they do in Sql Server query outputs, with a link to display the clickable xml, though there may be another approach i'm not considering (maybe a styled display of the xml data, etc.). Two things i'd like to know how to do

First, get the xml converted to a string, and display it in the table. Maybe the first 30 chars.
Finally, style the xml into something useful, like a clickable link to display the full xml, or a sub-table, or a styled string.

So the following works, and displays a nice table, with edit and delete links. But Xml fields are missing. How would you go about adding support for the Xml fields?

[Code]....

View 1 Replies

C# - LinqDataSource Bound To Dynamic List?

Aug 17, 2010

Im trying to create LinqDataSource that will represent data from dynamically created String list and then use it as a datasource to my GridView.

List<string> users = RetreiveUsers();
LinqDataSource ds = new LinqDataSource();

View 1 Replies

How To Refresh The Gridview After It Filters (Dynamic) Using LinqDataSource

Jul 29, 2010

AllowSorting="True" AutoGenerateColumns="False" DataSourceID="LinqDataSource1">

SortExpression="UserName" />
SortExpression="FullName" />
SortExpression="Email" />
SortExpression="LastLoginDate" DataFormatString="{0:dd MMMM yyyy}"/>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="MyDataContextDataContext" onselecting="LinqDataSource_Selecting">
<WhereParameters>
<asp:Parameter Name="Subject" />
</WhereParameters>
</asp:LinqDataSource>
public void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
this.LinqDataSource1.WhereParameters["Subject"].DefaultValue = this.txtSubject.Text;
e.Result = reporterRepo.GetInquiries();

View 2 Replies

LinqDataSource Dynamic Parameters - Forcing An Or With WhereParameters?

Jul 22, 2010

In my "selecting" statement I need to add two dynamic parameters when using the LinqDataSource's WhereParameters collection:

e.WhereParameters.Add(param, True)

However, the system adds these parameters as AND, but I want to perform an OR where either parameter 1 OR parameter 2 is true.

View 2 Replies

Forms Data Controls :: Create An ASP Grid With Dynamic Columns With An Ability To Freeze Columns And Rows

Sep 20, 2010

I created a gridview that is made up of 4 gridviews and using a stored procedure to populate it. I create columns at runtime because the number of columns changes all the time.To make the grids editable I am adding template fields at runtime as I create the columns, this is to ensure that a user is able to edit the cells and some foot values update. Reason why I have four grids is to freeze rows and columns like in excel using javascript. The problem is that performance is very bad especially in IE, the grids take a long time to load. I am not sure if this is caused by the data load or the creation of text boxes. see some of the code below for my _aspx page:

[Code]....

View 1 Replies

Binding Data From LinqDataSource To Textbox / How To Bind Texbox To One Property From Linqdatasource

Sep 1, 2010

How I can bind texbox to one property from linqdatasource?

I mean something like databinding contols in c# app

View 1 Replies

C# - Handling Dynamic Number Of Columns?

May 26, 2010

I'm developing a CMS of sorts, and I want to give my users the possibility of customizing the display. More precisely, I want to give them the ability to choose to display or hide the left column, the right column and/or the top div. The middle column cannot be hidden since this is where the actual content will show, whereas the other columns are for navigation or side menus.

I've been looking for a way to make this as smart and flexible as possible. For now I'm using a MasterPage, but that seems to be too constraining. For instance, with MasterPage you need to add a ContentPlaceHolder control in every of your ASPX pages.

What are the best practices in this area? I guess a simpler way of saying this would be "I want to create a template system over which I have complete control".

View 1 Replies

MVC :: Dynamic Columns For View At Runtime?

Nov 2, 2010

I finally got the DynamicLibrary issue nailed down I asked about in another post. The basic gist is that there's a project table that renders to a View. The user can, at runtime, choose the columns to display and the order in which they should be displayed. Here's the method that does the work:

[Code]....

This works great. The SerializeToCsv() method is an extension method I created for generic string lists. I used the jQuery UI bundle to create a sortable set of 'ul li' elements with checkboxes in them, which allows users to select which columns to show, and in what order. When the post happens, the current order the elements are in on the View is the order in which they're added to the FormCollection, so I don't need to do anything special to track ordering. So far, all is working according to my evil plans.

The problem I have now is how to render this in the View dynamically at runtime. It's very easy to check for the Model's property values and display them selectively, but not to reorder them. Off the top of my head, I can think of a few ways to do this, but none of them are very attractive. The first idea is to send the Model in as a collection of objects. The query that returns the data as shown above already has the columns returned in the order the user chose, so I could wrap them in objects and render them as string representations in the View. This is clunky, ugly, and won't give me the support for the actual data types boxed in the objects. I'd have to convert them all to strings in the service class and then wrap them in objects, because the View wouldn't know if it was dealing with a DateTime, string, int or whatever. I REALLY don't want to take this route. Can anyone give me some advice on a better way to reorder and selectively display columns at runtime?

View 17 Replies

How To Use Dynamic Columns Boundfield And Templatefield In Gridview

Aug 10, 2010

I'm using dynamic columns boundfield and templatefield in gridview, the GV embeded in a panel (autoscroll:auto;width:fixe), I fixed 3 columns to fit the panel's width , when I add exceed the 3 columns the width changes !

View 15 Replies

Data Controls :: DataList With Dynamic Columns

Apr 23, 2012

How to dynamically assign a datasource  to a DataList ?????????

For example suppose that we want to fetch data from the database table accordingly user interest and then bind the data to DataList Control........... How to do that?

View 1 Replies

SQL Server :: Dynamic Nullable Columns Depending On The Value Of A Column?

Feb 11, 2011

I have a master document which is composed of other document types (some are required and some are not). While the master document's status is "Draft" I need to ignore all not nullable constraints (because the writer may decide to work on one of the children
documents that is not required and save as draft).

The closest solution I found for this problem is check constraints but I have not yet to see an example of this in check contraint and I'm not even sure if this is possible. Has anyone implemented a similar solution with check constraints (or any other methods)?

View 2 Replies

Forms Data Controls :: Gridview Dynamic Columns Footer

Jan 11, 2011

I am dynamically binding dataset to a gridview(No Columns at design time) .I need to show Totals for some of the dynamically generated columns in the footer.

View 3 Replies

Crystal Reports :: How To Create Dynamic Columns / The Parameter Is Incorrect

Jul 30, 2010

I'm trying to create dynamic columns in the Crystal Report. The parameter fields are named column1,column2,column3.....

I tried below code and it gives me an error "The parameter is incorrect".

[Code]....

View 1 Replies

Linq To Sql - 4.0 Dynamic Data Generating Search Or Filtering For Each Columns?

Aug 3, 2010

I am using dynamic data entities linq to sql project. For my test project I have one table, with 10 columns and a single primary key for example. Almost all the columns are varchars.I can get the basic project up and running fine - update, delete, insert etc.ince it has no foreign keys, there are no search filters rendered. I was wondering if there was an easy way to generate a set of filters for the columns for this table. So a First name and last name search box. Is there a way to generate these filters for chosen columns and is there a way to generate these for all the columns

for example, above each of the columns in the grid there might be a text box ( I am not too fussed where the text boxes are rendered as such). Each of the text boxes will act as a filter for that column (doing a SQL 'like')

View 1 Replies

Forms Data Controls :: Best Way To Format A Columns In A Dynamic Gridview?

Jul 6, 2010

I have a Gridview with autogeneratecolumn = yes since the datasource always returns different columns of data.

However, except from left most column, all columns to the right should be formated to #,###.#

How could I format these columns to the right dynamically ?

View 2 Replies

Forms Data Controls :: Displaying Dynamic Columns With LINQ?

Jan 26, 2010

I have the following code:

[Code]....

With this code behind:

[Code]....

Initially, I wrote the GetTeamMember() method to display the FullName in the ItemTemplate.

Then as I wrote the EditTemplate, I needed to populate a DropDownList with a list of names (first and last). It was fairly easy using the LinqDataSource, however it currently only shows the LastName. I could write another method GetTeamMembers() to populate the ddlTeamMember with the data I want, but I thought maybe there's a better "LINQ" way.

So I'm looking for a better way to get FullName (i.e. Firstname + " " + LastName) into both lblTeamMember and ddlTeamMember.

Options I thought of are:

I could write a method GetTeamMembers() I write a StoredProc that returns the extra column Better way?

View 6 Replies

Forms Data Controls :: Tree View With Dynamic Columns?

Mar 15, 2010

I have a requirement where on the left hand side we have a tree view control and on the right hand we have dynamic columns.

Below screenshot gives an idea of the requirement. what is the best way to implement this?

Year1, Year2, Year3 are dynamic and are based on the user input.

View 2 Replies

Forms Data Controls :: Datagrid With Dynamic Columns & Rows

Dec 6, 2010

I put in my page 1 table like grid with this style:

header of columns are select from table persons(so number of them are dynamic)

header of each row are select from table goods(so number of them are dynamic)

in table , in each cell,show the price & the date ,that this person,buy this goods

for example,in may 2008 ,Jack&sara buy pencil.so in front of pencil&buttom of jack we write his price and in front of pencil&buttom of sara we write her price.

so this table has 2 column & 1 row

in may 2009,

Jack&sara buy pencil.so in front of pencil&buttom of jack we write his price and in front of pencil&buttom of sara we write her price.

and jhon buy pen & suzzan buy book so this table has 4 column & 3 row

Price Date

Price Date

Price Date

Price Date

Pencil

Pen

book

then I want in each cell,I have 1 CHECKBOX that user of my program,checked each on that want. how can I design my page?

is ther any component?or I must create <TABLE> dynamically

View 4 Replies

Forms Data Controls :: Dynamic Columns ItemTamples In Grid?

Nov 13, 2010

I have created Grid where in Columnsname come from Database and it will be generated from a setup page where Icreate column in SQL dynamically.

Now I wanted to have an idea about these grid. How to fetch data in this grid and how toinsert data into database.

View 1 Replies

Forms Data Controls :: Bind Repeater With Dynamic Columns?

Jul 6, 2010

I need to bind a repeater with data having indefinite number of columns. How can i do that? Do i have to create template class for that?

View 7 Replies

Data Controls :: Add Dynamic BoundField And TemplateField Columns In GridView

Aug 24, 2013

How to add dynamic columns in Gridview?

View 1 Replies

Forms Data Controls :: How To Craete Dynamic Columns In Grid View

Jan 28, 2011

I am working on the dynamic grid view(create dynamic columns).I need some thing like that given bellow in the fig:

columns1,2,3 are dynamic and the modules under the columns are also dynamic. to create grid like that.

Column1
Column2
Column3
Module1
Module2
Module3
Module4
Module5
Module6
Module7
Module8

View 2 Replies

Forms Data Controls :: Creating Dynamic Template Columns In Gridview?

Sep 14, 2010

how to create dynamic template columns in gridview .

I have writing some of the code but it gives me error

The type or namespace name 'GridViewLabelTemplatecould' not be found (are you missing a using directive or an assembly reference?)

I have paste some my code

[Code]....

View 8 Replies

Forms Data Controls :: Adding Dynamic Columns In An Existing Gridview?

Mar 2, 2011

I have a Gridview on my aspx page. On my page_load event I check for a record in the database, if the record exists for that row in the gridview I would like to add a new column in the same gridview and add a button control to it. This adding of new column in the Gridview should happen in the codebehind (c#). see the code I wrote for this, but when I run it, it does not create any column on the gridview page.

[Code]....

View 6 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved