Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 733
Abdul Basit Avatar asked Jul 22 '13 06:07

Abdul Basit


2 Answers

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

like image 83
Abdul Basit Avatar answered Sep 28 '22 03:09

Abdul Basit


Think of using CommandArgument.

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

and use it in ItemCommand Event as

int id = Convert.ToInt32(e.CommandArgument);
like image 43
burki Avatar answered Sep 28 '22 03:09

burki