Asp.Net Repeater ItemCommand dataitem is always null

In the rpt_ItemCommand repeater, the rpt_ItemCommand event e.Item.DataItem 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.

+4
source share
2 answers

The DataItem property is always null except for ItemDataBound ... its designed by Microsoft.

+5
source

Consider using CommandArgument.

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

and use it in ItemCommand Event as

 int id = Convert.ToInt32(e.CommandArgument); 
+5
source

Source: https://habr.com/ru/post/1492642/


All Articles