- 作者:xiaoxiao
- 发表时间:2020-12-23 10:52
- 来源:未知
DataGrid中加入审核功能及删除的确认对话框[图]pcsky(进哥)个人主页:http://www.soft123.comNewsCheck.aspx (前台代码)<asp:datagrid id=DataGrid1 Width="587px" AutoGenerateColumns="False" DataMember="article" DataKeyField="newsid" DataSource="<%# DsArt %>" runat="server" AllowPaging="True"> <HeaderStyle ForeColor="White" BackColor="#3A5C9F"></HeaderStyle> <Columns> <asp:BoundColumn DataField="newsid" SortExpression="newsid" HeaderText="ID号"> <HeaderStyle Width="50px"></HeaderStyle> </asp:BoundColumn> <asp:BoundColumn DataField="typename" SortExpression="typename" HeaderText="文章类型"> <HeaderStyle Width="100px"></HeaderStyle> </asp:BoundColumn> <asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="url" DataTextField="title2" HeaderText="文章标题"></asp:HyperLinkColumn> <asp:ButtonColumn Text="审核" DataTextField="shenghe" HeaderText="审核" CommandName="Check"> <HeaderStyle Width="50px"></HeaderStyle> </asp:ButtonColumn> <asp:HyperLinkColumn Text="修改" DataNavigateUrlField="newsid" DataNavigateUrlFormatString="newsEdit.aspx?ID={0}" HeaderText="修改"> <HeaderStyle Width="50px"></HeaderStyle> </asp:HyperLinkColumn> <asp:ButtonColumn Text="删除" HeaderText="删除" CommandName="Delete"> <HeaderStyle Width="50px"></HeaderStyle> </asp:ButtonColumn> </Columns> <PagerStyle NextPageText="下一页" PrevPageText="上一页" HorizontalAlign="Right" Mode="NumericPages"></PagerStyle></asp:datagrid>NewsCheck.vb (后台代码)Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound Dim btnDel As LinkButton Dim btnCheck As LinkButton
If Not (e.Item.ItemType = _ ListItemType.Header Or _ e.Item.ItemType = ListItemType.Footer) Then
' 在每个删除按钮上加上确认 btnDel = e.Item.Cells(5).Controls(0) btnDel.Attributes.Add("onClick", "return confirm('确定要删除这条记录吗?');")
' 审核按钮的处理 btnCheck = e.Item.Cells(3).Controls(0) If btnCheck.Text = 1 Then btnCheck.Text = "已审核" btnCheck.Enabled = False Else btnCheck.Text = "待审核" End If End If End Sub'注:文章未审核时,显示“待审核”按钮,点击后按钮变成灰色不可用的状态。