前台代码:
<asp:DataList ID="DataListResume" runat="server" OnItemDataBound="DataListResume_ItemDataBound" OnItemCommand="DataListResume_ItemCommand" DataKeyField="HR_ResumeInfoId"> <HeaderTemplate> <table> <tr> <td> 简历编号 </td> <td> 简历名称 </td> <td> 语言 </td> <td> 简历完整度 </td> <td> 简历状态 </td> <td> 更新日期 </td> <td> 默认简历 </td> <td> 操作 </td> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <%# DataBinder.Eval(Container.DataItem, "HR_ResumeInfoId")%> </td> <td> <%# DataBinder.Eval(Container.DataItem, "ResumeTitle")%> </td> <td> <%# DataBinder.Eval(Container.DataItem, "LanguageEdition")%> </td> <td> </td> <td> <%# DataBinder.Eval(Container.DataItem, "StateMean")%> </td> <td> <%# DataBinder.Eval(Container.DataItem, "ModifyDate", "{0:yyyy-MM-dd}")%> </td> <td> <%# DataBinder.Eval(Container.DataItem, "SetDefault")%> </td> <td> <asp:LinkButton ID="LBRefresh" runat="server" EnableViewState="False" OnClick="LBRefresh_Click">刷新</asp:LinkButton> <%--<asp:LinkButton ID="LBPreview" runat="server" EnableViewState="False" OnClick="LBPreview_Click">预览</asp:LinkButton>--%> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# EditUrl("ItemId",DataBinder.Eval(Container, "DataItem.HR_ResumeInfoId").ToString(),"Content") %>'>预览</asp:HyperLink> <%-- <asp:LinkButton ID="LBModify" runat="server" EnableViewState="False" OnClick="LBModify_Click">修改</asp:LinkButton>--%> <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# EditUrl("ItemId",DataBinder.Eval(Container, "DataItem.HR_ResumeInfoId").ToString(),"Detail") %>'>修改</asp:HyperLink> <asp:LinkButton ID="LBDownload" runat="server" EnableViewState="False" OnClick="LBDownload_Click">下载</asp:LinkButton> <asp:LinkButton ID="LBDelete" runat="server" OnClick="LBDelete_Click" CommandName="TheDelete" OnCommand="LBDelete_Command" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "HR_ResumeInfoId")%>'>删除</asp:LinkButton> </td> </tr> </ItemTemplate> <FooterTemplate> <tr> <td> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# EditUrl("Edit") %>'>新建简历</asp:HyperLink> </td> </tr> </table> </FooterTemplate> </asp:DataList>
后台代码:
protected void LBDelete_Click(object sender, EventArgs e) { LinkButton lbDelete = (LinkButton)sender; string ItemId = lbDelete.CommandArgument.ToString(); Response.Write("<script>alert(" + ItemId + ");</script>"); HR_ResumeInfo_Provider.DeleteHR_ResumeInfos(ItemId); BindResume(); } protected void LBDelete_Command(object sender, CommandEventArgs e) { LinkButton lbDelete = (LinkButton)sender; string ItemId = lbDelete.CommandArgument.ToString(); Response.Write("<script>alert(" + ItemId + ");</script>"); HR_ResumeInfo_Provider.DeleteHR_ResumeInfos(ItemId); BindResume(); } protected void DataListResume_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "TheDelete") { string ItemId = DataListResume.DataKeys[e.Item.ItemIndex].ToString(); Response.Write("<script>alert(" + ItemId + ");</script>"); } }
这三个事件我都试了,没一个管用啊,怎么回事,click事件取不到CommanArgument的值,linkbutton的command事件和datalist的command事件根本就没反应,哪位大神能帮我看看啊
事件写错了,应该写在datalist的事件中
我这里按你的方式 没什么问题啊 qq734209936 帮你看看