<asp:TemplateField HeaderText="name" SortExpression="Name">
<ItemTemplate>
<asp:Checkbox id="chkIsDeletable" runat="server" />
<asp:HiddenField id="hndFileId" runat="server" Value='<%#Eval("FileID")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="name" SortExpression="Name">
<ItemTemplate>
<%#Eval("filename") %>
</ItemTemplate>
</asp:TemplateField>
現在按鈕單擊事件:
protected void Button_Click(object sender, EventArgs e)
{
String SelectedFileIds ="";
foreach (GridViewRow item in GridView1.Rows)
{
CheckBox chkIsDeletable = item.FindControl("chkIsDeletable") as CheckBox;
HiddenField hndFileId = item.FindControl("hndFileId") as HiddenField;
if (chkIsDeletable.Checked)
SelectedFileIds = hndFileId.Value + ",";
}
SelectedFileIds = SelectedFileIds.TrimEnd(",");
}
現在您將擁有所有勾選checbox的文件ID,現在您可以從包含選定fileids的數據庫中刪除這些記錄。
希望它能幫助你!
請問你的問題**英文**如果你可以.. http://blog.stackoverflow.com/2009/07/non-english-question-policy/ –