<asp:GridView DataKeyNames="CategoryID" ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting"> <Columns> <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" /> <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" /> <asp:TemplateField HeaderText="Select"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("CategoryID") %>' CommandName="Delete" runat="server">Delete</asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> cs代码: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1"); l.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete this record " + DataBinder.Eval(e.Row.DataItem, "CategoryID") + "')"); } } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Delete") { int categoryID = Convert.ToInt32(e.CommandArgument); // get the categoryID of the clicked row // Delete the record DeleteRecordByID(categoryID); // Implement this on your own :) } } <asp:GridView DataKeyNames="CategoryID" ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting"> protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int categoryID = (int) GridView1.DataKeys[e.RowIndex].Value; DeleteRecordByID(categoryID); } /// <summary> /// 需求计划 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void dv_Result_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[12].Attributes.Add("onclick", "javascript:return confirm('是否确认删除?');"); } } 其中Cells[12]从0开始,包括隐藏列 <cc2:DataView ID="dv_Result" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" Width="841px" CssClass="DataViewControl" HorizontalAlign="Center" OnRowDeleting="dv_Result_RowDeleting" DataKeyNames="NextcheckPersonID" AllowPaging="True" OnPageIndexChanging="dv_Result_PageIndexChanging" OnRowDataBound="dv_Result_RowDataBound"> <FooterStyle BackColor="White" ForeColor="#000066" /> <Columns> <asp:BoundField DataField="WaitrequireID" HeaderText="计划流水号" /> <asp:BoundField DataField="requireDescribe" HeaderText="计划描述" /> <asp:BoundField DataField="establishDate" HeaderText="制单时间" /> <asp:BoundField DataField="DepartmentName" HeaderText="制单部门" /> <asp:BoundField DataField="establishPersonName" HeaderText="制单人" /> <asp:TemplateField HeaderText="编辑"> <itemtemplate> <a href="#" style="text-decoration:underline" οnclick="<%# string.Format("javascript:window.open('RequirementModify.aspx?WaitrequireID={0}','_blank','toolbar=no,height=400px,width=700px,resizable=yes,scrollbars=yes');",Eval("WaitrequireID")) %>" >编辑</a> </itemtemplate></asp:TemplateField> <asp:TemplateField HeaderText="查看详情"> <itemtemplate> <a href="#" style="text-decoration:underline" οnclick="<%# string.Format("javascript:window.open('RequirementQueryResult.aspx?WaitrequireID={0}','_blank','toolbar=no,height=400px,width=700px,resizable=yes,scrollbars=yes');",Eval("WaitrequireID")) %>" >查看详情</a> </itemtemplate></asp:TemplateField> <asp:BoundField DataField="spareID" HeaderText="备件编号" Visible="False" /> <asp:BoundField DataField="planNum" HeaderText="计划数量" Visible="False" /> <asp:BoundField DataField="NextcheckPersonName" HeaderText="下一个审批人" /> <asp:TemplateField HeaderText="审批"> <itemtemplate> <a href="#" style="text-decoration:underline" οnclick="<%# string.Format("javascript:window.open('RequireApprove.aspx?WaitrequireID={0}&NextSequence={1}&NextcheckPersonID{2}','_blank','toolbar=no,height=350px,width=600px,resizable=yes,scrollbars=yes');",Eval("WaitrequireID"),Eval("NextSequence"),Eval("NextcheckPersonID")) %>" >审批</a> </itemtemplate></asp:TemplateField> <asp:TemplateField HeaderText="审批意见"> <itemtemplate> <a href="#" style="text-decoration:underline" οnclick="<%# string.Format("javascript:window.open('ApproveNotionList.aspx?WaitrequireID={0}','_blank','toolbar=no,height=350px,width=600px,resizable=yes,scrollbars=yes');",Eval("WaitrequireID")) %>" >审批意见</a> </itemtemplate></asp:TemplateField> <asp:CommandField HeaderText="删除" ShowDeleteButton="True" /> </Columns> <RowStyle ForeColor="#000066" /> <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Center" /> <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" /> <EmptyDataTemplate> <p> <table> <tr> <td style="width: 3px"> <input id="Button2" type="button" value="button" /> <input id="Submit1" type="submit" value="submit" /></td> <td> </td> <td> </td> </tr> <tr> <td style="width: 3px"> </td> <td> </td> <td> </td> </tr> <tr> <td style="width: 3px"> </td> <td> </td> <td> </td> </tr> </table> </p> </EmptyDataTemplate> </cc2:DataView> |