问题比较难以表书,请大家帮忙看看 gridview和 sqldatasource都是自动生成的,现在我在gridview上新加了一列checkbox,并在个gridview外面加了一个删除按钮,我希望先checkbox选责一些行,然后点删除按钮,把这些行批量删除.主要是我不想用gridview自带的删除,怎么办?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 foreach(GridViewRow row in GridView1.Rows) { CheckBox chk = row.FindControl("MyCheckBoxID") as CheckBox; if(chk != null && chk.Checked) { // 此行被选中, object key = GridView1.DataKeys[row.RowIndex].Value; // 获取键 // 以下执行删除 ... }} Jinglecat(晓风残月 >> 问题需简洁,错误要详细,需求得明确)我的代码已经到了这个程度了,主要就是以下执行删除怎么办??我的sqldatasource是自动生成的后台 protected void Button3_Click(object sender, EventArgs e) { foreach (GridViewRow dvr in GridView1.Rows) { CheckBox cb = (CheckBox)dvr.Cells[4].FindControl("CheckBox1"); if (cb.Checked == true) { ??这里怎么写 } } }前台<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" OnRowCreated="GridView1_RowCreated" OnRowDataBound="GridView1_RowDataBound" PageSize="5" > <Columns> <asp:CommandField ShowEditButton="True" ShowSelectButton="True" /> <asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False" ReadOnly="True" SortExpression="ProductID" /> <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" /> <asp:BoundField DataField="UnitPrice" DataFormatString="{0:c}" HeaderText="UnitPrice" SortExpression="UnitPrice" /> <asp:TemplateField> <HeaderTemplate> <asp:CheckBox ID="CheckBox2" runat="server" Text="全选" OnCheckedChanged="CheckBox2_CheckedChanged" AutoPostBack="True" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#CCCC99" ForeColor="Black" /> <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" /> <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" /> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="Data Source=DLZ-18A1E0ACAFD;Initial Catalog=Northwind;User ID=sa" DeleteCommand="DELETE FROM Products WHERE (ProductID = @original_ProductID)" InsertCommand="INSERT INTO [Products] ([ProductName], [UnitPrice]) VALUES (@ProductName, @UnitPrice)" OldValuesParameterFormatString="original_{0}" ProviderName="System.Data.SqlClient" SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice] FROM [Products]" UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [UnitPrice] = @UnitPrice WHERE [ProductID] = @original_ProductID AND [ProductName] = @original_ProductName AND [UnitPrice] = @original_UnitPrice"> <DeleteParameters> <asp:Parameter Name="original_ProductID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="ProductName" Type="String" /> <asp:Parameter Name="UnitPrice" Type="Decimal" /> <asp:Parameter Name="original_ProductID" Type="Int32" /> <asp:Parameter Name="original_ProductName" Type="String" /> <asp:Parameter Name="original_UnitPrice" Type="Decimal" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="ProductName" Type="String" /> <asp:Parameter Name="UnitPrice" Type="Decimal" /> </InsertParameters> </asp:SqlDataSource> <br /> 晕 还有人么。。。 问个问题 图表制作问题加分帖 急问,为什么CSS丢失,而且网页不跳转 ASP.NET中为DataGrid添加合计字段 ASP。NET中怎么把网页的后缀名.aspx转成HTML网页文件 VS.NET再次求助 各位高手请教你们关于RadioButtonList的问题? 关于vs2003安装问题“vc软件包未找到或未注册“ 急!高分求解,用户控件里可以用Cookie和session吗? ADO.NET能否直接执行插入\修改\删除?而不要通过DATASET更新? 有关<input type="hidden".... C#写的许多个类和方法编译的DLL非托管要怎么调用?
CheckBox chk = row.FindControl("MyCheckBoxID") as CheckBox;
if(chk != null && chk.Checked) { // 此行被选中,
object key = GridView1.DataKeys[row.RowIndex].Value; // 获取键
// 以下执行删除 ...
}
}
后台
protected void Button3_Click(object sender, EventArgs e)
{
foreach (GridViewRow dvr in GridView1.Rows)
{
CheckBox cb = (CheckBox)dvr.Cells[4].FindControl("CheckBox1");
if (cb.Checked == true)
{
??这里怎么写
}
}
}
前台
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID"
DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" OnRowCreated="GridView1_RowCreated" OnRowDataBound="GridView1_RowDataBound" PageSize="5" >
<Columns>
<asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="UnitPrice" DataFormatString="{0:c}" HeaderText="UnitPrice"
SortExpression="UnitPrice" />
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" Text="全选" OnCheckedChanged="CheckBox2_CheckedChanged" AutoPostBack="True" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="Data Source=DLZ-18A1E0ACAFD;Initial Catalog=Northwind;User ID=sa"
DeleteCommand="DELETE FROM Products WHERE (ProductID = @original_ProductID)"
InsertCommand="INSERT INTO [Products] ([ProductName], [UnitPrice]) VALUES (@ProductName, @UnitPrice)"
OldValuesParameterFormatString="original_{0}" ProviderName="System.Data.SqlClient"
SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice] FROM [Products]"
UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [UnitPrice] = @UnitPrice WHERE [ProductID] = @original_ProductID AND [ProductName] = @original_ProductName AND [UnitPrice] = @original_UnitPrice">
<DeleteParameters>
<asp:Parameter Name="original_ProductID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="original_ProductID" Type="Int32" />
<asp:Parameter Name="original_ProductName" Type="String" />
<asp:Parameter Name="original_UnitPrice" Type="Decimal" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
</InsertParameters>
</asp:SqlDataSource>
<br />