PDA

View Full Version : استفاده از رویداد OnItemCreated در Repeater



persianboy62
شنبه 16 خرداد 1388, 17:36 عصر
با سلام من می خوام با استفاده از رویداد OnItemCreated در یک Repeater اطلاعات مربوط به هر سطر رو درج کنم. برای اینکار کد زیر رو نوشتم ولی هر بار که اجرا می کنم روی سطری که به رنگ قرمز مشخص کردم پیغام خطا میده. پیغام خطا رو هم زیر کد نوشتم. لطفا اگر کسی می دونه مشکل کجاست راهنمایی کنه.




protected void RptUserList_ItemCreated(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
var oRow = e.Item.DataItem as DataRowView;

//Row number
((Literal)e.Item.FindControl("LitRows")).Text = (RptUserList.Items.Count + 1).ToString();

if (oRow != null)
{
//User name
((Literal) e.Item.FindControl("LitUserName")).Text = oRow["userName"].ToString();
}

}
}


پیغام خطا:



Unable to cast object of type '<>f__AnonymousType5`6[System.Guid,System.String,System.String,System.Boo lean,System.Boolean,System.String]' to type 'System.Data.DataRowView'.

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.InvalidCastException: Unable to cast object of type '<>f__AnonymousType5`6[System.Guid,System.String,System.String,System.Boo lean,System.Boolean,System.String]' to type 'System.Data.DataRowView'.