PC Review


Reply
Thread Tools Rate Thread

Accessing DataRow from inside DataBind Event

 
 
shamila
Guest
Posts: n/a
 
      16th Sep 2005
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.DateTime"))
{
DataRow oDR;
if(Convert.ToDateTime(dc) ==DateTime.MinValue)
s="";
else
s= String.Format("{0:d}",Convert.ToDateTime(dc));
}
return s;
}

 
Reply With Quote
 
 
 
 
Scott Roberts
Guest
Posts: n/a
 
      16th Sep 2005

"shamila" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
shamila
Guest
Posts: n/a
 
      19th Sep 2005
"Scott Roberts" wrote:
>"shamila" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> 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
 
Reply With Quote
 
shamila
Guest
Posts: n/a
 
      19th Sep 2005
"Scott Roberts" wrote:
>"shamila" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
checkboxlist inside a formview databind with objectdatasource(Please somebody help me) Jai Microsoft ASP .NET 0 25th Sep 2006 02:18 PM
checkboxlist inside a formview databind with objectdatasource Jai Microsoft ASP .NET 0 24th Sep 2006 05:09 PM
databind to datarow Maziar Aflatoun Microsoft ASP .NET 4 29th Sep 2005 03:22 PM
Textbox inside a repeater. how to access datarow in post back event. guoqi zheng Microsoft ASP .NET 1 10th Jun 2005 12:59 PM
How to change a DataRow inside an event handler? DJM Microsoft ADO .NET 2 9th Apr 2004 05:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:18 PM.