C# - Bind Non-property To Datagrid Column DataField?

Mar 31, 2011

Let's say I have a DataGrid that looks something like:

<asp:DataGrid ID="SomeDataGrid"
runat="server">
<Columns>
<asp:BoundColumn HeaderText="A Header" SortExpression="Sort" DataField="Data"></asp:BoundColumn>
</Columns>
</asp:DataGrid>

In this Grid, I set the datasource to some collection that contains a public property called "Data" and do a databind(). Every works as expected.Now let's say I want to set the DataField attribute of the column to a public member, or a property, or some other thing I've computed. What is the easiest way to go about this without creating intermediate objects or adding public properties to the objects in the collection?So what I want to do is something like:

<asp:BoundColumn HeaderText="A Header" SortExpression="Sort" DataField="someMethod()"></asp:BoundColumn

View 1 Replies


Similar Messages:

Forms Data Controls :: Datagrid Bind To Indexed Property?

Aug 5, 2010

I'm trying to bind indexed property to the datagrid control.

Here is my class which has a normal property ('p0') and 2 indexed properties ('p1' & 'p2'). I need to bind p1 and p2 as column in the datagrid.

[Code]....

View 2 Replies

Forms Data Controls :: Can Bind Any Type Of System.Collection To DataSource Property Of A DataGrid

Nov 11, 2010

can we bind any type of System.Collection to DataSource property of a DataGrid ?

View 6 Replies

Bind Datafield To Dropdown List With Hard Coded Values?

Jan 19, 2010

I have a dropdown list with hard coded values:

<asp:ListItem Text="One Day Shoots" Value="1" />
<asp:ListItem Text="Multi-day Shoots" Value="2" />

I want to use this to insert and edit values from a db. For example when adding a record the user selects 'One Day Shoots' and 1 gets inserted into the database. Then if the user goes to edit the page since the value in the db is 1 then the 'One Day Shoots' is selected.

One way I considered accomplishing this was by using a hidden feild - when the user selects something in the dropdown list the field is updated with the value, then when the user actually adds the record the value in the feild is submitted. I'm pretty sure this would work but is there a better way?

View 3 Replies

Forms Data Controls :: Bind Datafield Of Gridview To Link Button?

May 26, 2010

I want to bind the datafields of the gridview to the linkbuttons.

In a column i want to display the links.

I have created gridview dynamicaly.

View 4 Replies

C# - Datagrid Button Column - How To Bind A Function To A Button

Dec 25, 2010

Currently i have a datagrid view that displays names in the 1st columnnd in the 2nd column delete buttons.

This datagrid view already has bind data to a function so it can displays the names that are withint a xml file (first column is a hyperlink column).

But next i want to be able to delete the xml values that are in the first column.(by clicking on the delete button on the second column of it)

<name></name>

But how do i exactly bind a (delete) function to these buttons?

name1 btnDelete
name2 btnDelete
etc...

View 2 Replies

Forms Data Controls :: Gridview BoundField Or DataField Has To Be Filled With The Value That Comes From Column1 Or Column?

Feb 4, 2010

I'm using a DataSet to fill my gridview. The dataset contains several columns, like: direction - fromNumber - toNumberThe column direction can contain the values "incoming" or "outgoing". In my gridview, I would like to show only 2 columns, direction and from/to. If direction = "incoming", the values from fromNumber has to be inserted in "from/to". If direction = "outgoing", the values from toNumber has to be inserted in "from/to".I know I can use a TemplateField to show different text values in a column...But I have no idea how to do this when I want to show the values from a column...

<asp:BoundField DataField="direction" HeaderText="direction" HtmlEncode="false" />

[Code]....

View 2 Replies

Moving Items In Datagrid From One Column To Another Column?

Jul 8, 2010

I have a grid containing images loaded from database. the images are displayed in the order as they are stored in the database. Is there any way to change the order of the images manually once after they are uploaded to the database.. the admin before publishing the images to front end, should be able to arrange the images as he/she wish and then finally stores them in database.

View 5 Replies

C# - Bind Datagrid To Collection?

Jan 20, 2010

how do I bind a DataGrid to a collection? (e.g : List ). i used this :

Datagrid dg = new Datagrid();
dg.DataSource = myCollection;
dg.DataBind();

but after this, the Datagrid still doesn't display the data from the collection.

View 5 Replies

Mvc - Bind DataGrid To Dictionary In C#?

May 6, 2010

I end up with a row for each object in the list, and any cell in a given row is bound to a property of the corresponding object.

However, suppose one of the properties of my object is a dictionary, and each is expected to contain a specific key. Is there any way to bind one of my DataGridColumns to that dictionary key?

View 3 Replies

Forms Data Controls :: Datagrid With Column Choose To Choose Columns Dynamically Using DataGrid With Object Data Sour

Sep 30, 2010

I have "Order" object with Columns Ticket,OTP and CustomerName etc.Intially on DataGrid, I'm binding Ticket only , when user clicks on "Column Chooser" button, another windows appears to pickup CustomerName,OTP columns to add specified column dynamically on Datagrid. Environment : Asp.net ,C# with Object Data source

Public Class Order
{
publc void Order()
{
}
public string Ticket
{
get
{
return this.strTicket;
}
set
{
this.strTicket = value;
}
}
public string OtpNumber
{
get
{
return this.strOtpNumber;
}
set
{
this.strOtpNumber = value;
}
}
public string CustomerName
{
get
{
return this.strCustomer;
}
set
{
this.strCustomer = value;
}
}
}
}

View 1 Replies

AJAX :: Bind Datagrid Using Javascript/XMLHTTP?

May 25, 2010

How do i bind datagrid(server control) using javascrip/XMLHTTP.

View 2 Replies

Forms Data Controls :: Bind A Datagrid To A Reportviewer?

Mar 26, 2011

I have a datagrid called studentAddList which is combined by 2 tables. Now I have a reportviewer called ReportViewer1. They are both placed on the same page. Now I would like to bind the datagrid studentAddList to the reportviewer ReportViewer1. The reason why I bind the datagrid to it is because I have some filtration on the data.

View 5 Replies

Forms Data Controls :: Can’t Bind Dataset To Datagrid

Dec 26, 2010

i have a buuton .i want to when click on button my result show on grid. i can show result in dataset but i can`t bind dataset to datagrid. i write:

[Code]....

View 7 Replies

Forms Data Controls :: Using Objectdatasource To Bind Datagrid?

Jun 14, 2010

I am using objectdatasource to bind datagrid,i m using select method of objectdatasource and manage paging (page size 10) and command event also,i have define MaximumRowsParameterName and StartRowIndexParameterName but now problem is when i am trying to delete 11th record from second page and again bind same grid than i coudn't fine rest of 10 records and get no records found.

View 1 Replies

Forms Data Controls :: Bind ArrayList To DataGrid And Reference Them?

Jul 23, 2010

I have an ArrayList of strings called 'vins'. I have set DataGrid1's data source set to 'vins'. When I check off create columns automatically at runtime the DataGrid is populated with the correct values from the arraylist, however I'm not sure how to reference them. I'm trying to make it so that a user can click on a link after any VIN number and have that referenced and deleted from the arraylist. bind this ArrayList to the DataGrid and then be able to reference them.

View 4 Replies

C# - Bind Property GridView

Nov 20, 2010

I would like to show the title and the price of a movie in my Gridview. The title and price are properties from the class Movie and Movie is a property of the class CartItem. Here is the Code of my gridview

<asp:GridView ID="gvShoppingCart" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" />
<asp:BoundField DataField="Price" HeaderText="Price" />
</Columns>
</asp:GridView>

The DataSource of my gridview is List<CartItem>. This are the classes

public class CartItem
{
private Movie _movieInCart;
private int _Count;
public CartItem()
{ }
public CartItem(Movie movie, int count)
{
_movieInCart = movie;
_count= count;
}
public Film MovieInCart
{
get { return _movieInCart; }
set { _movieInCart = value; }
}
public int Count
{
get { return _count; }
set { _count = value; }
}
public double getSubTotal()
{
return _movieInCart.Price * _count;
}
}
public class Movie
{
private string _title;
private double _price;
public string Title
{
get { return _title; }
set { _title= value; }
}
public double Price
{
get { return _price; }
set { _price= value; }
}
//More properties here
}

Apparently the GridView shows only first level properties, but how do I show these second level properties.

View 1 Replies

Bind Value Of Property To Result Of Some Method?

Oct 27, 2010

I need to bind an ASP.NET control something like so:

<asp:label ID="lblName" Text=<%# GetName()) %>

and in CodeBehind file I have this method:

protected string GetName()
{
...
}

Is this right, or how I can do something like this?

View 2 Replies

VS 2010 Bind Enabled To Property

Jun 12, 2012

I have several controls on a page that I want to bind the enabled property to a couple of properties in code behind that are set on Page_Load. Here's an example of what I'm using to bind to the properties.

Code:
<telerik:RadComboBox ID="AssignToRadComboBox"
runat="server"

[code]...

This works fine once the page is posted back for the first 4 controls on the page.Here's the 1st control that doesn't get disabled like I expect it to. The expression is the same in the Enabled property so I'm not sure why it isn't working.

Code:
<telerik:RadComboBox ID="CategoryRadComboBox"
runat="server"
Skin="Web20"
Width="225px"
Enabled='<%# IsAdmin && !IsCompleted %>' />

I've got 2 problems with this approach:

1. I need it to happen the first time the page is loaded rather than after a postback.

2. I need it to work for all of the controls on the page having the expression.

It's too late in the development process to rewrite the page so I can't use jQuery & knockoutjs for example to do this all on the client side.

View 2 Replies

Forms Data Controls :: Show Datagrid Vertically - Property Not Working

Jan 10, 2010

i am using datadrid and i want to display it in vertically but it is continiously showing in horizontally style. i have made changes in view , property but still not working.

View 2 Replies

How To Compare A Row And Column In A Datagrid Using C#

Oct 8, 2010

I have 2 datsets named ds and ds1 and merged that datasets into a single table named dt. Now, i want to compare the first dataset row value with second dataset column values For Ex: 1 dataset row contains the value as "SriDevi" means, i want to compare and find how many times the value "SriDevi" appears in second dataset columns and count the appearance. And give the answer as the "count".

[code]....

View 1 Replies

AJAX :: DataView - How To Bind To The Rows Property

Jan 30, 2010

I have a json service method that returns an object with two properties. The first property is called Rows and contains the list of objects I want to bind to the dataview. The second property is TotalRowCount. It is a paging method. How can I tell the DataView to bind to the Rows property? This is what I have so far...

[code]....

View 1 Replies

How To Bind DetailsView Field To Function Instead Of Property

Aug 5, 2010

Is it possible to display the result of a function instead of the value of a property in a DetailsView Field?

<asp:Label ID="m_LabelPlantCode" runat="server" Text='<%# Bind("PlantCode") %>'></asp:Label>
<asp:Label ID="m_LabelPlantCode" runat="server" Text='<%# Bind("PlantCode(true)") %>'></asp:Label>

View 2 Replies

Usercontrol Int Property Bind To A Null Value From Database?

Dec 1, 2010

I have build a usercontrol in asp.net, and there is a property like the following.

Everything works fine when the bound value is an integer. However, if the bound field return a null from database, it will return a invalid cast error.

change to a nullable int is not desirable because it changes the how programmer work with the control's property in code-behind.

[code]....

View 2 Replies

C# - Bind SelectedValue Of DropDownList To Nested Property?

Feb 10, 2010

I have a asp.net FormView with a DropDownList for the selection of a month. The FormView is data bound to an ObjectDataSource.

<asp:DropDownList ID="MonthsList" DataSourceID="MonthsListDataSource" DataTextField="Value" DataValueField="Key" SelectedValue='<%# Bind("OrderDate.Month") %>' Width="100" runat="server" />

I like to bind the selected value to the nested property 'Month' of 'OrderDate' as shown above. The property OrderDate is of type DateTime. The error I'm getting while binding to a nested property is:

A call to Bind was not well formatted. Please refer to documentation for the correct parameters to Bind.

View 2 Replies







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