datagrid中,如果想要删除之前确认一下是否删除,该怎么写呢?
nnh 2003-08-22 08:46:44 看到別人的帖子http://expert.csdn.net/Expert/topic/2144/2144111.xml?temp=.7131159
我也想實現這樣的功能.可是我照上面說的代碼做,不行,高手幫我改一改我的代碼吧.謝謝.
我的代碼:
sub Data_Del(obj as object, e as DataGridCommandEventArgs)
Dim MyCommand As OleDbCommand
Dim DeleteCmd As String = "DELETE from news where id = @Id"
MyCommand = New OleDbCommand(DeleteCmd, MyConnection)
MyCommand.Parameters.Add(New OleDbParameter("@Id", OleDbType.VarChar, 11))
MyCommand.Parameters("@Id").Value = MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))
MyCommand.Connection.Open()
MyCommand.ExecuteNonQuery()
MyCommand.Connection.Close()
try
Mydatagrid_DataBind()
catch
Mydatagrid.CurrentPageIndex=MyDataGrid.pagecount-1
Mydatagrid_DataBind()
end try
End sub
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="500"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
AutoGenerateColumns="False"
AllowPaging="true"
pageSize="10"
OnPageIndexChanged="Mydatagrid_PageIndexChanged"
DataKeyField="id"
OnDeleteCommand="Data_Del"
>
<Columns>
<asp:TemplateColumn HeaderText="Bigclass" >
<ItemTemplate>
<asp:Label id="id" width="30" runat="server" Text='<%# Container.DataItem("bigclass") %>'/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Title">
<ItemTemplate>
<a href='dropdownlist_listnews.aspx?id=<%#DataBinder.Eval(Container.DataItem,"id")%>' target=_blank>
<%# DataBinder.Eval(Container.DataItem,"Title").ToString()%>
</a>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Del" CommandName="delete" ButtonType="PushButton"/>
</Columns>
</asp:DataGrid>
請問實現這個功能的代碼在什么地方加呀?(代碼最好寫在同一程序中.)