62,254
社区成员
发帖
与我相关
我的任务
分享
<asp:GridView ID="GrdAds" runat="server"
AutoGenerateColumns="False" CellPadding="2"
CellSpacing="1" EnableViewState="False" Font-Names="宋体"
Font-Size="10pt" GridLines="None"
Width="778px" datakeynames="ID" AllowPaging="True"
onpageindexchanging="GrdAds_PageIndexChanging" PageSize="20" onrowdeleting="GrdAds_RowDeleting"
>
<Columns>
<asp:BoundField HeaderText="客户名称" />
<asp:BoundField HeaderText="联系电话" />
<asp:BoundField HeaderText="联系地址" />
<asp:BoundField HeaderText="投放日期" />
<asp:BoundField HeaderText="截至日期" />
<asp:TemplateField>
<ItemTemplate>
<%--此去编写绑定的代码--%>
<tr>
<td>
<asp:HyperLink ID="HyperLinkCode" Text='<%# Eval("CustomerName") %>' NavigateUrl='<%# "EditPage.aspx?id="+Eval("ID") %>'
runat="server" />
</td>
<td>
<%# Eval("Tel") %>
</td>
<td>
<%# Eval("Address") %>
</td>
<td>
<%# Eval("RunTime") %>
</td>
<td>
<%# Eval("EndTime") %>
</td>
<td>
<asp:LinkButton ID="LinkDel" runat="server" CommandName="delete" CommandArgument='<%#Eval("ID") %>'>删除</asp:LinkButton> //这个就是我定义的删除按钮
</td>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void GrdAds_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//这里是后台代码,为什么我在这里设置断点,点击删除,根本就没跳到这里来,也就是说,我自己定义的删除按钮根本就没执行后台代码,怎么解决啊 ?
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string strConnnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
strConnnection += Server.MapPath("..\\db\\quanguo.mdb");
OleDbConnection myconn = new OleDbConnection(strConnnection);
//GridView1.DataKeyNames = new string[] { "id" };
myconn.Open();
GridView1.DataKeyNames = new string[] { "shiid" };
//使用 Value 属性确定记录的主键值。
//设置
String shiid = GridView1.DataKeys[e.RowIndex].Value.ToString();
String sql = "delete from shi where shiid =" + shiid;
//Response.Write("<script>alert('dddd')</script>");
DataSet ds = new DataSet();
OleDbCommand delcmd = new OleDbCommand(sql, myconn);
try
{
delcmd.ExecuteNonQuery();
Response.Write("<script>alert('删除成功')</script>");
}
catch (OleDbException ex)
{
}
myconn.Close();
// sda.Fill(ds, "shengb");
//重新绑定
this.GridView1.DataSource = myBind();
this.GridView1.DataBind();
// myconn.Close();
}