Use DataBinder.Eval(Object, String) Method with the column index, not the column's name

I can save a lot of processing if I can use the Column Index instead of the Column Name:

<%#DataBinder.Eval(CType(Container, DataGridItem).DataItem, <Column Index number here instead>)%>

 Is it possible?

0
jjmonty
4/17/2008 4:17:34 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1614 Views

Similar Articles

[PageSpeed] 22

then you can directly use <%# Container.DataItem(0)%>, <%# Container.DataItem(1)%>


Raghu
(MCSD.NET, MCAD.NET, MCDBA)
[Don't forget to click on Mark as answer on the post that helped you ]
0
rmaiya
4/17/2008 5:28:06 PM

Thanks Raghu !

I did not realise that "Container" refered to the DataSource like that.

0
jjmonty
4/17/2008 5:56:31 PM

Raghu, do you know how to get the name of the column from <%# Container.DataItem(0)%>?

Container.DataItem(0).ID and Container.DataItem(0).Name don't work.

0
jjmonty
4/17/2008 7:54:34 PM
Reply:

Similar Artilces:

Gridview
Gridview - how to find a column by it's column name rather than it's Cell index Hello Friendshow to find a column by it's column name rather than it's Cell indexi.e i want to do something likestrFirstName = Grid1.Rows[2].Cells["FirstName"]In the project i am working on gets customized to different customers....so the position of the columns keep changing depending on the customers requirement.hardcoding..like below is a pain to maintainif i use Grid1.Rows[2].Cells["1"]Can some body help..regardsSara Hi, columns do not get associated names exactly like that. Nearest equivalent w...

SqlBulkCopy: the locale id '0' of the source column '<column name> ' and the locale id '1033' of the destination column '<column name>' do not match.
Hi, I am using the sqlbulkcopy object to transfer large amount of data from one SQL server to Other. The code look like this.. SqlDataReader readerSrc = null;SqlBulkCopy bulkCopy = new SqlBulkCopy(connDest);//Prepare Destination Table.SqlCommand cmdDelete = new SqlCommand("DELETE FROM " + destTableName, connDest);//Set the sqlcommand textSqlCommand cmdGet = new SqlCommand("SELECT * FROM " + srcTableName, connSrc);//Open source connection.connSrc.Open();//Open destination connection.connDest.Open();int delete = cmdDelete.ExecuteNonQuery();//Get the data.readerSrc = cmdGet.ExecuteRead...

DataBinder.Eval is saying my column doesn't exist, probably because it has a brackets [ ] in the column name
I am using a SQL command in ASP.NET to send a query to a an OLAP cube that returns a dynamic set of data that I load into a datatable and then bind to a GridView. I have made my own ITemplate implementaton for displaying and formatting the data, and the following line is causing me  problems: RawValue = DataBinder.Eval(row.DataItem, "[Month].[Month].[MEMBER_CAPTION]")  The error returned is: Month is neither a DataColumn nor a DataRelation for table My guess as to what is happening is that it sees the brackets in the field name and stops reading the field name at [Mo...

how to get a control ID from a bind field name / bound field (column) name from a formview's control
I have a form view which is bound to a table, now from codebehind file I need to apply some formatting based on some of the field's bound control. For example, if Formview1 is bound to Employee table, and it's item template has a control with ID "Label1" which is bound to "EmployeeJoinDate" . Now, I have a different table which has a list of field name(EmployeeJoinDate is one of them), all of which should be applied some formatting based on some condition. Now I can take two approach for that, but I am stuck at both:  1. If I can somehow get the contro...

How to use a full column name (table name and column name) with a DataReader
Hi, I have a problem retrieving the data with a DataReader from a stored proc that performs a join of two table with the same column's names but different data. Let me explain with an example: I have two tables: Table1: Id, Name Table2: Id, Name, IdTable1 The sproc is something like this: CREATE PROCEDURE [dbo].[SearchByName] (@Name nvarchar(40)) AS BEGIN SELECT * FROM dbo.Table1, dbo.Table2 WHERE Table1.Id = Table2.IdTable1 AND Table1.Name LIKE '%' + @Name + '%' END And my c# code is something like this: Database db = Databas...

How to use dynamic column name in DataBinder.Eval()?
I am creating a template column programmatically and want to add a user control to the ItemTemplate of the column.The usual syntax used is:<asp:Label id="DataLabel" runat="server" text='<%# DataBinder.Eval(((DataGridItem)Container).DataItem, "ColumnName")%>' />Is there a way to allow the column name to be dynamically declared in the above syntax? Ofcourse. On what does the column name you want to use depend? Lets say you have a datatable with 3 columns: 1) ColumnToUse 2) ColumnA 3) ColumnB - ColumnToUse contains either "ColumnA" or "ColumnB". Your code could then look like t...

Replace 1's and 0's in a gridview column with Yes's and No's
Is it possible to change the display of a column in a gridview to show a Yes for all 1's and a No for 0's that display in a particular column of a gridview bound to a database?  If so, can someone share the way with me?  I am using ASP.NET 2.0 with VB Code Behind.  Thanks One way you can do is thrrough  CASE in your select statement: Select YesNoColumn= CASE yourColumn WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' ELSE '' END FROM YourtableLimno <Columns>     <asp:TemplateField HeaderText="yourHeader" SortExpression="yourDataField"> ...

How to set visible property of Gridview columns using column name instead of index
How to  set visible property of Gridview  columns using column name instead of index Dear janacpp, the columns collection of gridview has no indexer for column name. So you can do something like that:  in your code section you want to set the visible property add this code : GridView1.Columns[GridView1.Columns.IndexOf(GetField("FieldName"))].Visible=false;  where FieldName is the name of your field. and add this function:DataControlField GetField(string name) {DataControlFieldCollection fields = GridView1.Columns.CloneFields();for (int i = 0; i < f...

Can anyone see why I'm getting this error The column prefix 'dbo.PropertyForRentLocalized' does not match with a table name or alias name used in the query.
 Could someone please explain the likely root cause of this error.Thanks, andy. Server: Msg 107, Level 16, State 3, Line 16The column prefix 'dbo.PropertyForRentLocalized' does not match with a table name or alias name used in the query.Server: Msg 107, Level 16, State 1, Line 16The column prefix 'dbo.PropertyForRentLocalized' does not match with a table name or alias name used in the query.Server: Msg 107, Level 16, State 1, Line 16The column prefix 'dbo.PropertyForRentLocalized' does not match with a table name or alias name used in the query. CREATE ...

why a string column with a '' value synchronize from ASE to ASA, in ASA it's value become ' ' with a blank in it?
"darcy.zhai" <zhaizy@e-future.com.cn> wrote in news:43967064@forums-2-dub of sybase.public.sqlanywhere.mobilink: Please try to ask your question in the _body_ of the post, not the subject line. There are many people that never really look at the subject line (like myself most of the time). > why a string column with a '' value synchronize from ASE to ASA, in > ASA it's value become ' ' with a blank in it? This has to do with nullability. First, connect to ASE via ISQL and try the same query ML is executing. What is returned? An...

The filter control 'CategoryFilter' does not support this operation because it is associated with an unsupported column 'Name'.
 I tried thisusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web.DynamicData;using System.Xml.Linq;using System.Web;using System.Web.Security;using System.Data;using System.ComponentModel.DataAnnotations;using System.Web.UI;using System.Web.UI.WebControls;using System.ComponentModel;using Microsoft.Web.DynamicData;namespace Sodexo.Entities{    [MetadataType(typeof(AssetMetaData))]    public partial class Asset    {            }    [...

Find the column name using child's reference
Hi, I just explaining my doubt using a realtime code as follows: I have a nested report which encapsulates two child report "report1", "report2". dw_print.GetChild("report1",ldwc_child) ldwc_child.SetTransObject(sqlca) ldwc_child.Retrieve() ls_filter = "nmpref_userid ='"+ls_userid+"'" ldwc_child.setfilter(ls_filter) ldwc_child.Filter() But purposely I deleted a report named "report2", then using the same reference "ldwc_child" , I have done the following code dw_print.GetChild("report2&qu...

The column prefix 'g' does not match with a table name or alias name used in the query.
Hello, does anyone knows that, I have this problem in 3 websites, the others .. runs ok WIN 2000 - SQL 2000 The column prefix 'g' does not match with a table name or alias name used in the query. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: The column prefix 'g' does not match with a table name or alias name used in the query. Source Error: An unhandled exception was...

The column prefix 'g' does not match with a table name or alias name used in the query
Still dont work does anybody can help?.. I only changed the connection string on the web.config.. like user and database name .. nothing else Installing DotNetNuke Version: 03.00.12 Current Settings Default Provider SqlDataProvider Connection String Server=(local);Database=DotNetNuke3012;uid=dotnetnuke;pwd=****; ..NET Framework Version 1.1.4322.2032 Windows User DREAMSERVER2\ASPNET Host Name dreamserver2 Installation Status Report 00:00:00.140 - Installing Version: 3.0.12 00:00:00.140 - Installing Script: DotNetNuke.SetUp.SqlDataProvider 00:00:0...

Web resources about - Use DataBinder.Eval(Object, String) Method with the column index, not the column's name - asp.net.presentation-controls

Resources last updated: 12/16/2015 12:38:13 AM