Three things I can see here...

 ListItemType itemType = (ListItemType)e.Item.ItemType;

doesn't require a cast

Junk this...
 if (itemType == ListItemType.Header || itemType ==
ListItemType.Footer || itemType ==
ListItemType.Separator)
                       {
                               return;
                       }

rewrite this
 string temp =
((DataRowView)e.Item.DataItem).Row.ItemArray[2].ToString();

as

DataRowView dr = (DataRowView)e.Item.DataItem;
string temp = dr[2].ToString();

and make sure that the data type in [2] supports the ToString() method
 -- it should, but you never know.

This will at least let you see where the cast is failing.




On Apr 1, 2005 11:57 AM, christopher andrada <[EMAIL PROTECTED]> wrote:
> 
> 
> Cut and paste the code and still getting same error.
> By the way... thanks for helping me.
> 
> public void OnItemDataBoundEventHandler(object sender,
> DataGridItemEventArgs e)
>                {
>                        ListItemType itemType =
> (ListItemType)e.Item.ItemType;
>                        if (itemType == ListItemType.Header || itemType ==
> ListItemType.Footer || itemType ==
> ListItemType.Separator)
>                        {
>                                return;
>                        }
>                        if (itemType == ListItemType.Item || itemType ==
> ListItemType.AlternatingItem)
>                        {
>                                string temp =
> ((DataRowView)e.Item.DataItem).Row.ItemArray[2].ToString();
>                        }
>                }
> 
> [InvalidCastException: Specified cast is not valid.]
> 
> dataDisp.dataGrid.dataGrid2.OnItemDataBoundEventHandler(Object
> sender, DataGridItemEventArgs e) in
> c:\inetpub\wwwroot\datadisp\datagrid\datagrid2.aspx.cs:63
> 
> System.Web.UI.WebControls.DataGrid.OnItemDataBound(DataGridItemEventArgs
> e) +110
>   System.Web.UI.WebControls.DataGrid.CreateItem(Int32
> itemIndex, Int32 dataSourceIndex, ListItemType
> itemType, Boolean dataBind, Object dataItem,
> DataGridColumn[] columns, TableRowCollection rows,
> PagedDataSource pagedDataSource) +181
> 
> System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
> useDataSource) +1411
> 
> System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs
> e) +49
>   System.Web.UI.WebControls.BaseDataList.DataBind()
> +23
>   dataDisp.dataGrid.dataGrid2.bindDataGrid() in
> c:\inetpub\wwwroot\datadisp\datagrid\datagrid2.aspx.cs:50
>   dataDisp.dataGrid.dataGrid2.Page_Load(Object
> sender, EventArgs e) in
> c:\inetpub\wwwroot\datadisp\datagrid\datagrid2.aspx.cs:32
>   System.EventHandler.Invoke(Object sender, EventArgs
> e) +0
>   System.Web.UI.Control.OnLoad(EventArgs e) +67
>   System.Web.UI.Control.LoadRecursive() +35
>   System.Web.UI.Page.ProcessRequestMain() +750
> 
> 
> --- Dean Fiala <[EMAIL PROTECTED]> wrote:
> > You need to test the type of the DataGridItem first
> >
> > if(e.Item.ItemType == ListItemType.Item ||
> > e.Item.ItemType ==
> > ListItemType.AlternatingItem)
> > {
> > //your code
> >
> > }
> >
> > On Apr 1, 2005 1:35 AM, christopher andrada
> > <[EMAIL PROTECTED]> wrote:
> > >
> > > hi all,
> > >
> > > i'm getting an error "Specified cast is not valid"
> > in
> > > the code below.
> > >
> > > public void OnItemDataBoundEventHandler(object
> > sender,
> > > DataGridItemEventArgs e) {
> > >
> > > // this is the line where the error occurs.
> > > string temp =
> > >
> >
> ((DataRowView)e.Item.DataItem).Row.ItemArray[1].ToString();
> > > }
> > >
> > > please help.
> > >
> > > Thanks,
> > >
> > > chris
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam?  Yahoo! Mail has the best spam
> > protection around
> > > http://mail.yahoo.com
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> >
> >
> > --
> > Dean Fiala
> > Very Practical Software, Inc
> > http://www.vpsw.com
> >
> 
> __________________________________
> Yahoo! Messenger
> Show us what our next emoticon should look like. Join the fun.
> http://www.advision.webevents.yahoo.com/emoticontest
> 
> 
> Yahoo! Groups Links
> 
> 
> 
> 
> 


-- 
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to