Sorting A GridView Column Related To Other Table?

Jun 10, 2010

i have a GridView bound to a DataView. Some columns in the DataView's table are foreignkeys to related tables(f.e. Customer). I want to enable sorting for these columns too, but all i can do is sorting the foreignkey(fiCustomer) and not the CustomerName.

I have tried this without success(" Cannot find column ERP_Customer.CustomerName "):

<asp:TemplateField HeaderText="Customer" SortExpression="ERP_Customer.CustomerName" >

A tried also the DataViewManager, but i've a problem to detect the table to sort:

[code].....

I have to apply the sort on a distinct table of the DataViewManager, but this table would differ on the related tables.

I have bound the TemplateColumns in Codebehind in RowDataBound-Event f.e.:

Dim LblCustomer As Label = DirectCast(e.Row.FindControl("LblCustomer"), Label)
LblCustomer.Text = drCharge.ERP_CustomerRow.CustomerName 'drCharge inherits DataRow

What is the recommended way to sort a GridView on columns related to other tables? I could build a custom datatable with the customername instead of the foreignkey and bind this column to the TemplateField. But then my huge dataset in the model makes no sense anymore.

EDIT: I have a model with a Dataset. I'm binding one Datatable(ERP_Charge) from it to my GridView(actually i take a Dataview from that Table). In this Datatable are columns that are related to other Datatables in the Dataset(relations are defined). When i want to make the grid sortable its no problem on the columns that belong to ERP_Charge.

But the columns with foreign keys to other table could not be sorted because the Gridview shows f.e. not the CustomerID but the Customername. I get the Customername in RowDataBound. Normally i would join the tables and add a Datacolumn for the Customername.

View 1 Replies


Similar Messages:

Forms Data Controls :: Gridview Column With Data From Related Table In SQL Db?

Aug 18, 2010

I've got a gridview that is databound with LINQ in the code behind. One column shows the id from the table. I would like to show a more human friendly product name that is associated with that id number but is from another table. Thought I had it figured out by entering a Template field in the gridview tags (in the .aspx page) and an item template within that with

<ItemTemplate>
<%Eval(Products.productName")%></ItemTemplate>

but when I try to build it says this can only be done in the context of a databound control.

Can I add this column within the gridview tags or does it have to be done from the code behind?

View 3 Replies

C# - Get Field Descriptions From A Parent Related Table In A Gridview

Aug 6, 2010

What would be the best way to set a gridView.DataSource for LINQ query with some foreign keys and get fields in the parent tables? Like this:

The table BOOK have a Author_Id, which is related to table Author

class:

public IQueryable<Book> ListAll()
{
RENDBDataContext db = new RENDBDataContext();
var result = from b in db.Books
orderby b.Id descending
select b;
}
code-behind:
grdBooks.DataSource = vBooks.ListAll();
grdBooks.DataBind();

In the ASPX page I can get to the Author name with the [asp:TemplateField], using <%Eval("Author.Name")%>

What I'm looking for is a better solution, that doesn't involve changes in the aspx page

View 1 Replies

C# - Sorting Specific Column In A GridView After A DataBound?

Feb 9, 2010

I have given an access to stored procedure, which i'm not able to edit. This Stored Procedure returns a Table with 2 Column, what I did is set a GridView's DataSource using SQLDataSource in this stored procedure. but I want this GridView to Sort an specific column to descending whenever this GridView Loads.

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource2" ForeColor="Black"
Width="58%" Height="125px" AllowPaging="True" AllowSorting="True"
PageSize="5" >
<Columns>
<asp:BoundField DataField="DateOccur" HeaderText="Login Date"
SortExpression="DateOccur" />
<asp:BoundField DataField="TotalMinutesPlayed" HeaderText="Total Minutes"
SortExpression="TotalMinutesPlayed" />
</Columns>
<AlternatingRowStyle BackColor="#EFEFEF" />
</asp:GridView>

View 2 Replies

How To Gridview Sorting - Column Data Vanishes

Aug 18, 2010

I have a Gridview, which I bind to a Dataview programtically. My Gridview has 11 columns. Sorting works fine as long as I do not remove any columns programtically.

In certain cases I remove 2 of the columns from the Gridview. Still not a problem. All the data is properly displayed however the problem occurs when I sort one of the columns. I sort the Dataview and bind to the Gridview again. Data from two of my columns just vanishes. Both of these columns are based on ItemTemplates. The columns are still displayed but just empty cells.

View 1 Replies

Data Controls :: Implement Column Sorting In GridView

Apr 19, 2013

I have a gridview with 10 columns , i want sort the gridview column and im using bound field and template field

How can i make a sorting in grid in ASP.Net using VB.Net?

View 1 Replies

Forms Data Controls :: Sorting Gridview Column Templatefield?

Jun 16, 2010

i want to sort a gridview column which is a template field with a repeater control in it. this column has multiple links and i would like to sort using the first link. how can i achieve this.

here is my code:

<asp:TemplateField HeaderText="Groups">

View 2 Replies

Forms Data Controls :: Sorting Date Column In Gridview?

Mar 19, 2010

In gridview columns im displaying date and time, as below.

23/02/2010 11:19:52

Im also doing sorting on these columns.

But the issue is during sorting its only sorting on "day (dd)"....

for example....these 3 values are from column, Date.

23/02/2010 11:19:52

18/02/2010 10:25:10

17/03/2010 09:30:51

when I click for "Ascending" sort....it should get "17/03/2010 09:30:51" on the top (because of month 03) others have 02, but it doesnt, it gets in the above order, its just sort on day (dd).Below is my code for boundfield....

<asp:BoundField
DataField="Date"
HeaderText="Date" [code]...

View 6 Replies

Forms Data Controls :: Sorting Using The Column Header Of A Gridview?

Jul 7, 2010

Dear all; I have the following gridview

Type Cost

BENZ 40,000

TOYOTA 20,000

Now, I would like a situation if either TYPE or Cost is clicked on, it would sort things in ascending order. see example below.

if Cost is clicked on, we will have the following sorting order.

Type Cost

TOYOTA 20,000

BENZ 40,000

I am still new to visual studio.net.

View 13 Replies

Forms Data Controls :: GridView Sorting Text On Column

Feb 21, 2011

I am trying to change the text in the header column when the GridView is sorted by checking the SortedDirection of the GridView.

problem: The text in the header column gets changed after i have clicked three times to sort the GridView.

i don't understand my problem. it seems really simple to get it work...this is what i done on each databound

[Code]....

View 15 Replies

Forms Data Controls :: Sorting Not Available In A Dynamically Binded Column Of A GridView?

Jun 21, 2010

I have a auto column generated GridView in a page, I have a dynamically binded column in that gridview, when page loads then sorting option is available on all other columns except that dynamically created column.

[Code]....

View 1 Replies

Forms Data Controls :: Gridview Sorting Unbound Column In Bound Grid

May 14, 2010

I have a gridview control bound to a sqldatasource in c#. In the rowdatabound event I look at a value in a cell and use a function to evaluate the value and depending on that value I populate an added unbound column in my bound datagrid to show an excalmation point. I now want to sort by the column with the excalmation point.

View 2 Replies

Forms Data Controls :: GridView Editing Not Working Properly After Sorting On Any Column

Jun 2, 2010

whn i click edit button on grid before sorting on any column it is working properly...but once i click on any column for sorting n thn click on edit then the rows get sorted again and edit is set on some other row... plz help me...herez my code..

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
gv_photo.EditIndex = e.NewEditIndex;
bindgrid("album_id");
public void bindgrid(string sort)
string str = "select * from tbl_Album";
[code]...

View 2 Replies

Forms Data Controls :: Sorting A Column By Simply Clicking On The Column Rather Than Clicking On The Column Header?

Jan 14, 2010

I am looking to sort a column on my gridview by simply clicking on the column rather than clicking on the column header. In the design I have been given, the column header will not be shown, and I need to be able to give the user to sort this column, by simply just clicking any where on the column.

View 2 Replies

Forms Data Controls :: How To Show Data From A Related Table In A Gridview / Entitydatasource

Feb 23, 2011

I am using an ADO Entity Model for my ms-sql database.

My database has a Resellers table which has ResellerID (primary key, int) and Name columns along with other data.

I also have an Orders table which contains OrderID (primary key, int), OrderDate, ResellerID (foreign key to Resellers.ReselerID).

If I just do a query like:

[Code]....

I am able to reference order.Reseller.Name just fine with no problems.

However I have an EntityDataSource on my page as follows:

[Code]....

Notice the Include="Reseller" attribute in the datasource... I also have a GridView tied to that datasource as follows: I cut some of it off for breavity:

[Code]....

Now what I have listed above will run with no errors, but what I want to do is replace the column that displays "ResellerID" with the equivilant to order.Reseller.Name. In other words I want my grid to display the reseller's name rather than the numeric ID.

I have tried to change the DataField to "Reseller.Name" but that will generate the following error:

A field or property with the name 'Reseller.Name' was not found on the selected data source.

Is there anyway to do this without me writing a custom select statement in my code behind?

View 2 Replies

SQL Server :: How To Copy One Column Data From A Table To Another Table Column With Rest Of The Column

Jan 16, 2011

I want to copy data from a table[tblExcel][No.of columns:2] to another table[ev_event] which has 5 columns, 2 columns from the another table, 3 columns from user defined value

[code].....

View 4 Replies

Forms Data Controls :: Paging On A Different Column Than The Sorting Column

Sep 26, 2010

Situation: SQL database, Linq to SQL class a ASP.NET page with a LinqDataSource and a gridview. The table has a ID field, a date field and a Serialnr field. In my Grid I like to Page on the datefield but to sort on the serialnr field ( or a selectable other field). Is that possible? Standard the paging is always done on the sort field and when you select a different sort field the page jumps back to the first page., and paging is then done over that sorted column.

View 2 Replies

Forms Data Controls :: Getting The Custom Sorting And Paging With Images To Indicate The Sorting Direction In Gridview

Jul 18, 2010

Moderators Note: THIS ISSUE IS BIG FOR ME AND EVEN IF POSSIBLE, GET THE REPLY FROM THE DESIGNER OF GRIDVIEW. I have been looking for him for long. I am really fed up with reviewing a good lot of web pages on how we can possibly customize the gridview to enable sorting and paging. So many sites have listed out a lot of information and so many guidances. But the problem is that one works out fine and the other is a burden. I really feel bad about being given the job of customizing this kind of a gridview which has no user friendly approach to it. Also, this control is rendered without the pager links inside the <tfoot> tag. I have tried the Pear Pager in php. It is that good and easy to use and compared to that, the gridview in asp.net is the worst ever control i have ever tried so far.

1. i can use the images to indicate the sorting direction
2. I can have the custom pager like

[code]

<<Previous 1 2 3 .. 7 Next >>.

[/code]

When i click the next when i am viewing the page at 3 , the pager links should change as

[code]

<<Previous 2 3 4 .. 7 Next >>

[/code]

Kindly look into this type of requirement and firstly tell me whether this is possible with the gridview control. I would like this request even to be escalated to the designers of the gridview control also, so that Microsoft comes out with a reply THAT WORKS and not the kind of stuff like surfing through a lot of links and pages and finally wasting a lot of days precious time and still breaking the head with this useless control. I have spent a lot of time in searching for a perfect way. Not writing a code that is non-standard. I am really serious b'cos I have spent weeks in customizing this control. If I dont get a solid reply atleast now, I am going to generate all the output by HTML content by custom coding.

View 7 Replies

ADO.NET :: Display Value From Related Table?

Jan 18, 2011

I have 2 tables:

User(Id PK, TitleId FK, Name, Active)

Title(Id PK, Text)

Title is a lookup table of titles (Mr, Miss,...) and its got a relationship with table User by TitleId.

Now I'm trying to display the data in a web page using .net and Entity Framework. I'm using a ListView control and a query as a source. it all displays fine except for the Title.

Here is my code:

MyEntities _entities = new MyEntities (); User user = new User(_entities); IQueryable u = (from x in _entities.Users where x.Active == true select x); ListView1.DataSource = u; ListView1.DataBind();

and the code in the front end:

<asp:ListView ID="ListView1" runat="server" EnableModelValidation="True" DataKeyNames="Id"><ItemTemplate> <tr> <td> <%# Eval("Id") %> </td> <td> <%# Eval("Title.Text") %> </td> <td> <%# Eval("Name") %> </td> </tr></ItemTemplate><LayoutTemplate> <table ID="itemPlaceholderContainer" runat="server"> <tr runat="server"> <th id="Th2" runat="server"> Id</th> <th id="Th1" runat="server"> Title</th> <th id="Th3" runat="server"> Name</th> <th runat="server"> </tr> <tr runat="server" ID="itemPlaceholder"> </tr> </table></LayoutTemplate>

How do I manage to get the Title Text associated with a User to display on the ListView?

View 4 Replies

MVC :: How To Get Related Table Data / How To Access Groups Table Data From View

Mar 30, 2010

I have a strongly typed view for Contacts table In my index page , i am accessing the tables as --- "foreach (var item in Model)"

This table has an association with Groups Table

How can i access Groups table data from view.

intellisense gives me possibility to write like "item.Groups.GroupTitle"

But it returns null(object not initiated) How to solve this?

View 3 Replies

ADO.NET :: Select Name Column From The Applicant Table And Value Column From ApplicantValue Table?

Feb 2, 2011

I am quite new to LINQ, and I am stuck with this probably basic problem, but haven't been able to find a solution, so I thought I could ask here.

So, I have this repository where I put my functions for data accessing, and now I need to write a function to get all the applicants that have applied for this particular advertisement, and their values too. Now, the values are stored in a separate M:N table, where every row consists of the applicantID,advertisementID and value. I just wanna append the value to every applicant that I show, so that it would look like a Ranking List.

However, I do not seem to know how to select just the name column from the Applicant table, and just the Value column from the ApplicantValue table.

And there's this Iqueryable interface that further confuses me...

Here's my function to get the Applicants only:

[Code]....

Now, if I try to add to the definition of the type two columns, it says that it only messes with types, i.e. one type should be passed. So I figured I would do a ViewModel and then pass it, like this

[Code]....

and then in the function I have no idea how to pass the values:

View 5 Replies

ADO.NET :: Checking For Valid Related Table Data In EF?

Nov 7, 2010

I've always been a bit unsure how to check for the existance of properly referenced table data.

In my situation I have various tables related to each other in many-to-one relationships where the "1" side can be deleted without the reference fields on the "many" side being updated (nulled).

I have FK relationships set up in my MS SQL server database but have turned off the FK constraint enforcement (and cascading update/delete) so that I can delete records from the "1" side but leave the keys for those deleted records in the records on the "many" side. This is something I really need to do for my web app design.

View 1 Replies

DataSource Controls :: Get Record Count With Related Table?

May 17, 2010

I want to get record count from below example.

I made two tables. One is club_info and another one is club_members.

And each table has data like following

[club_info]
club_id
club_name
:
[club_members]
mem_id
club_id
:

I want to get club_name and the member count for selected club_id and want to return the result as sqldatareader.

View 8 Replies

Display A Gridview Using Select Statement Of Two Column In One Table?

Oct 24, 2010

I'm using asp.net and c# language.

How can i display a GridView using select statement of two column in one table?

This is my coding:

if (sdr.Read())
{
if(namaPembekal.Equals(sdr["namaPembekal"]) && tarikhRo.Equals(sdr["tarikhRo"]))
{
Session.Add("namaPembekal",sdr["namaPembekal"]);
Session.Add("tarikhRo", sdr["tarikhRo"]);
if((((String)(Session["namaPembekal"])).Equals("namaPembekal")) && ((String
(Session["tarikhRo"])).Equals("tarikhRo"))
GridView1.DataSourceID = SqlDataSource2.ID;
GridView1.DataSourceID = txtJourneyDate.Text;
}

View 1 Replies

C# - Separate Table Column Into Multiple GridView Columns?

Nov 19, 2010

I am retrieving a column from a table using an SqlDataSource in ASP.NET/C#, which contains multiple 'values' separated by commas. I'd like to be able to separate this values into multiple columns in my GridView, and also allow them to update them. Is this easy to accomplish?

View 1 Replies







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