asp:GridView ID="GridView1" runat="server" Width="100%" EmptyDataText="暂时无数据" BorderColor="White" OnRowDeleting="GridView1_RowDeleting">
Columns>
asp:TemplateField HeaderText="选择">
ItemStyle Width="20px" />
ItemTemplate>
asp:CheckBox id="id" runat="Server" />
/ItemTemplate>
/asp:TemplateField>
asp:BoundField DataField="id" HeaderText="序号" >
ItemStyle Width="20px" />
/asp:BoundField>
asp:TemplateField HeaderText="标题">
ItemStyle Width="400px" />
ItemTemplate>
a href="../shangpu/%#eval_r("pageurl") %>" target="_blank">%#eval_r("title") %>/a>
/ItemTemplate>
/asp:TemplateField>
asp:TemplateField HeaderText="发表时间">
ItemStyle Width="100px" />
ItemTemplate>
%# Convert.ToDateTime(eval_r("addtime")).Date.ToString("yyyy-MM-dd") %>
/ItemTemplate>
/asp:TemplateField>
asp:HyperLinkField DataNavigateUrlFormatString="shangpu_edit.aspx?id={0}" Text="修改" NavigateUrl="shangpu_edit.aspx?id={0}" DataNavigateUrlFields="id" >
ItemStyle Width="30px" />
/asp:HyperLinkField>
asp:CommandField ShowDeleteButton="True" HeaderText="删除" DeleteText="div id="de" onclick="JavaScript:return confirm('确定删除吗?')">删除/div>" >
ItemStyle Width="30px" />
/asp:CommandField>
/Columns>
EmptyDataTemplate>
font color=red>暂时无数据/font>
/EmptyDataTemplate>
RowStyle Height="20px" />
/asp:GridView>
protected void btndeleteall_Click(object sender, EventArgs e)
{
string sqltext = "(";
for (int i = 0; i GridView1.Rows.Count; i++)
{
CheckBox chb = (CheckBox)GridView1.Rows[i].FindControl("id");
if (chb.Checked)
{
sqltext = sqltext + GridView1.DataKeys[i].Value.ToString() + ",";
}
}
sqltext = sqltext.Substring(0, sqltext.Length - 1) + ")";
sqltext = "delete from shangpu where id in" + sqltext;
string sqlcon = ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection con = new SqlConnection(sqlcon);
con.Open();
SqlCommand cmd = new SqlCommand(sqltext, con);
try
{
int count = Convert.ToInt32(cmd.ExecuteNonQuery());
if (count > 0)
{
viewbind();
MessageBox.Show(this, "删除成功,共删除" + count + "条记录!");
}
}
catch
{
MessageBox.Show(this, "删除失败!");
}
finally
{
con.Close();
con.Dispose();
}
}