我的母版页中有一个scriptmanager,我的内容页面有一个gridview和btndelete我想点击btndelete删除所选数据并刷新gridview并且btndelete不在更新面板中 我很试试,但我的代码工作非常糟糕,请帮助我:((
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="Blue" BorderStyle="Solid" CellPadding="3" DataSourceID="SqlDataSource1"
ForeColor="Black" GridLines="Vertical" Width="656px" >
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="check1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="picname" HeaderText="picname" SortExpression="picname" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="#99FF66" Font-Bold="True" ForeColor="Black" BorderColor="#006600" />
<PagerStyle BackColor="#33CC33" ForeColor="#0066FF" HorizontalAlign="Center" BorderStyle="Dashed" />
<RowStyle BackColor="Lime" />
<SelectedRowStyle BackColor="#0066CC" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btndelete" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="btndelete" runat="server" Text="Delete" OnClick="btndelete_Click" />
这是我的btndelete的cs代码:
protected void btndelete_Click(object sender, EventArgs e)
{
ArrayList mylist = new ArrayList();
string id = string.Empty;
int j = 0;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cb = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("check1");
if (cb != null)
{
if (cb.Checked)
{
id = GridView1.Rows[i].Cells[1].Text;
mylist.Add(id);
}
}
}
}
delet(mylist);
}
private void delet(ArrayList a) {
SqlConnection con2 = new SqlConnection();
con2.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["photogaleryConnectionString"].ToString();
SqlCommand cmd = new SqlCommand("delete from picture where picname =" + "@picname", con2);
foreach (string s in a)
{
cmd.Parameters.AddWithValue("picname", s.ToString());
con2.Open();
cmd.ExecuteNonQuery();
con2.Close();
}