简体   繁体   中英

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.

除了ItemDataBound之外,DataItem属性始终为null ...它是由Microsoft设计的。

Think of using CommandArgument.

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

and use it in ItemCommand Event as

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM