I want to get at the item that is being data bound, during the ItemDataBound event of an asp:repeater.
I tried the following (which was an unaccepted answer in a stackoverflow question):
protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Object dataItem = e.Item.DataItem;
...
}
but e.Item.DataItem
is null.
How can I access the item being data bound during the event called ItemDataBound. I assume the event ItemDataBound happens when an item is being data bound.
I want to get at the object so I can take steps to control how it is displayed, in addition the object may have additional helpful properties to let me enrich how it is displayed.
Tool had the right answer. The answer is that e.Item.Data
is only valid when e.Item.ItemType
is (Item, AlternatingItem). Other times it is not valid. In my case, I was receiving ItemDataBound events during header (or footer) rows, where there is no DataItem:
protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
// if the data bound item is an item or alternating item (not the header etc)
if (e.Item.ItemType != ListItemType.Item &&
e.Item.ItemType != ListItemType.AlternatingItem)
{
return;
}
Object dataItem = e.Item.DataItem;
...
}
You should assign RadGrid. DataBind(); method to RadTextBox. TextChanged even. So you will get your ItemDataBound event fires.
The ItemDataBound event is raised after an item is data bound to the DataList control. This event provides you with the last opportunity to access the data item before it is displayed on the client. After this event is raised, the data item is no longer available.
The ItemDataBound event occurs for each new item that is added to the Items collection of RadTimeline when it is bound. This event only occurs if the items are loaded from a data source (the DataSource or DataSourceID property is set).
I just wanted to add that I did accomplished this by doing the following:
protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//determine if the row type is an Item
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
DataRowView row = (DataRowView)e.Item.DataItem;
if (row["RowName"].ToString() == "value")
{
//INSERT CODE HERE
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With