Abdul Basit
Abdul Basit

Reputation: 722

Asp.Net Repeater ItemCommand dataitem is always null

In repeater rpt_ItemCommand Event the e.Item.DataItem is always null.

Here is the code behind:

protected void rpt_ItemCommand(Object sender, RepeaterCommandEventArgs e)
{
    DataRowView drv = (DataRowView)e.Item.DataItem // here the DataItem is Null.
}

Suggest me any solutions.

Upvotes: 5

Views: 4605

Answers (2)

burki
burki

Reputation: 79

Think of using CommandArgument.

<asp:LinkButton ToolTip="Delete" CommandArgument='<%#Eval("Id") %>' ....

and use it in ItemCommand Event as

int id = Convert.ToInt32(e.CommandArgument);

Upvotes: 6

Abdul Basit
Abdul Basit

Reputation: 722

The DataItem Property is always null except ItemDataBound... its by design of Microsoft.

Upvotes: 9

Related Questions