1.前台代码:给ImageButton控件里CommandArgument属性赋值,并且在ListView上添件onitemediting事件
<asp:ListView ID="lvwSubsidizeList" runat="server" onitemediting="lvwSubsidizeList_ItemEditing" > <ItemTemplate> <tr> <td height="30"> <%# Eval("ProjectName")%> </td> <td> <%# DateTime.Parse(Eval("ApprovalDate").ToString()).ToString("yyyy-MM-dd")%> </td> <td align="center"> <asp:ImageButton ID="ibtnEdit" runat="server" ImageUrl="/Images/btn_edit.png" CommandName="Edit" CommandArgument='<%# Eval("ID") %>' /> </td> </tr> </ItemTemplate> </asp:ListView>
2.后台代码:
protected void lvwSubsidizeList_ItemEditing(object sender, ListViewEditEventArgs e) { EnterpriseSubsidizeBLL enterpriseSubsidizeBLL = new EnterpriseSubsidizeBLL(); //查找ListView中ImageButton ImageButton ibtn = this.lvwSubsidizeList.Items[e.NewEditIndex].FindControl("ibtnEdit") as ImageButton; //取出CommandArgument值 int subID = int.Parse(ibtn.CommandArgument.ToString()); //根据ID取出数据对象 DAL.T_EnterpriseSubsidize subsidize = enterpriseSubsidizeBLL.GetEnterprisieSubsidizeInfo(subID); //项目名称 this.txtProjectName.Text = subsidize.ProjectName;
//批复时间 this.txtApprovalDate.Text = subsidize.ApprovalDate.ToString(); }