For Programmers: Free Programming Magazines  


Home > Archive > C# > August 2004 > Invalid cast on using DataRowView









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Invalid cast on using DataRowView
delew2

2004-08-17, 9:29 pm

Hi,

I'm trying to use a dropdownlist in a datagrid edit mode. I'm trying to preselect the initial item in the dropdownlist and using the following code...

public void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.EditItem)
{
DataRowView myDataRowView = (DataRowView)e.Item.DataItem;
string currentstatus = myDataRowView["Status"].ToString();
DropDownList myDropDownList = (DropDownList)e.Item.FindControl("DropDownList1");
myDropDownList.SelectedIndex = myDropDownList.Items.IndexOf(myDropDownList.Items.FindByText(currentstatus));
}
}

I keep getting "Specified cast is not valid." error for...
DataRowView myDataRowView = (DataRowView)e.Item.DataItem;


Can anyone help??

Thanks...
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com