473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Accessing DataRow from inside DataBind Event

we are trying to pass a value to format a value in the datacolumn. But
when we pass the datacolumn , it does not give me the value in the
column, instead gives me the column name.

the following code gives me an error invalid cast .

protected void ItemDataBoundEventHandler(object
sender,DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item ||
e.Item.ItemType==ListItemType.AlternatingItem)
{
for (int i = 2; i < oDT1.Columns.Count; i++)
{
DataColumn dc = oDT1.Columns[i];
string s = FormatDataColumn(ref dc);
e.Item.Cells[i-2].Text= s;

}
}
}

protected string FormatDataColumn( ref DataColumn dc)
{
string s;
if(dc.DataType==System.Type.GetType("System.DateTi me"))
{
DataRow oDR;
if(Convert.ToDateTime(dc) ==DateTime.MinValue)
s="";
else
s= String.Format("{0:d}",Convert.ToDateTime(dc));
}
return s;
}

Nov 17 '05 #1
3 1502

"shamila" <sh************@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
we are trying to pass a value to format a value in the datacolumn. But
when we pass the datacolumn , it does not give me the value in the
column, instead gives me the column name.

the following code gives me an error invalid cast .

protected void ItemDataBoundEventHandler(object
sender,DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item ||
e.Item.ItemType==ListItemType.AlternatingItem)
{
for (int i = 2; i < oDT1.Columns.Count; i++)
{
DataColumn dc = oDT1.Columns[i];
string s = FormatDataColumn(ref dc);
e.Item.Cells[i-2].Text= s;

}
}
}


What is "oDT1"? You should probably be using e.Item.DataItem.

The type of e.Item.DataItem will vary depending on what is bound to the
DataGrid.
Nov 17 '05 #2
"Scott Roberts" wrote:
"shamila" <sh************@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googleg roups.com...
we are trying to pass a value to format a value in the datacolumn. But when we pass the datacolumn , it does not give me the value in the
column, instead gives me the column name.

the following code gives me an error invalid cast .

protected void ItemDataBoundEventHandler(object
sender,DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item ||
e.Item.ItemType==ListItemType.AlternatingItem)
{
for (int i = 2; i < oDT1.Columns.Count; i++)
{
DataColumn dc = oDT1.Columns[i];
string s = FormatDataColumn(ref dc);
e.Item.Cells[i-2].Text= s;

}
}
}


What is "oDT1"? You should probably be using e.Item.DataItem.

The type of e.Item.DataItem will vary depending on what is bound to the
DataGrid.


oDT1 is a a datatable. I cannot access the Datatype if i use
e.Item.DataItem.


shamila

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 17 '05 #3
"Scott Roberts" wrote:
"shamila" <sh************@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googleg roups.com...
we are trying to pass a value to format a value in the datacolumn. But when we pass the datacolumn , it does not give me the value in the
column, instead gives me the column name.

the following code gives me an error invalid cast .

protected void ItemDataBoundEventHandler(object
sender,DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item ||
e.Item.ItemType==ListItemType.AlternatingItem)
{
for (int i = 2; i < oDT1.Columns.Count; i++)
{
DataColumn dc = oDT1.Columns[i];
string s = FormatDataColumn(ref dc);
e.Item.Cells[i-2].Text= s;

}
}
}


What is "oDT1"? You should probably be using e.Item.DataItem.

The type of e.Item.DataItem will vary depending on what is bound to the
DataGrid.


oDT1 is a a datatable. I cannot access the Datatype if i use
e.Item.DataItem.


shamila

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
3
by: DonRex | last post by:
Hello all! I couldn't find a web application-newsgroup for ASP.NET, so I'm sorry if this is the wrong forum! Synopsis: In my webform I have 3 nested repeaters: rpWeeks ----- rpTime
4
by: patrick_a | last post by:
Hello, I am trying to insert multiple instances of a custom user control into a placeholder on an aspx page, based on the records retrieved from the database. I use the datareader to loop through...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
1
by: Mikkel Olsen | last post by:
Hi. I have a problem regarding to the DataGrid_ItemDataBound event. I cant run this event when my datagrid is inside a DataList. The ItemDataBound for DataList1 is working well, but it never...
0
by: vbMental | last post by:
I created a user control that, had a datalist with checkboxes inside of the item template. These checkboxes would not retain state. For instance, if I set them to checked inside of the load event...
2
by: Jeff | last post by:
Hi - I have an ASP.NET web page accessing a SQL database. It works fine on the web, and I'm trying to get it to also work in debug mode in the IDE. The "on the web" page and my SQL database...
1
by: guoqi zheng | last post by:
Dear sir, I have a textbox inside a repeart control, autopostback set to true for that textbox. When the value of this textbox changes, I need to access current row and update database. ...
3
by: John | last post by:
Hi I have a hidden (visible=false) column on a gridview bound to a sql server table. I am trying to access the field as; For Each row As GridViewRow In grdEvents.Rows If row.RowType =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.