能实现不定数目的DataGrid的增删吗?

lyqof908 2004-08-27 06:40:32
现在客户有个页面要求如下:

首先列出所有大类,然后在每个大类下以表格显示具体的数据,
每个表格的行前都有个CheckBox.

然后点删除Button时,就把打了勾的行从数据库中删除.

现在问题是:

用DataGrid的话,怎么知道用户选择的是哪一个具体DataGrid中的一行??

而且大类的个数也不定(从DB中取),也没办法用DataGrid吧?
...全文
77 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lyqof908 2004-08-28
  • 打赏
  • 举报
回复
thanx
yanminhua123 2004-08-27
  • 打赏
  • 举报
回复
up
lang11zi 2004-08-27
  • 打赏
  • 举报
回复
string sql = "Delete from yourTable where id in (" + ids + ")";

跟asp里一样呀
brightheroes 2004-08-27
  • 打赏
  • 举报
回复
if(ids.Length > 1)
{
ids = ids.SubString(0,ids.Length -1);//去掉最后一个","
}

string sql = "Delete from yourTable where id in (" + ids + ")";

.....执行这个sql就可以了
brightheroes 2004-08-27
  • 打赏
  • 举报
回复
严重同意楼上的做法

当然,也可以在服务器端完成这个任务

string ids = "";

foreach(DataGridItem dgi in this.DataGrid1.Items)
{
CheckBox cb = (CheckBox)dgi.FindControl("yourCheckBoxId");
if(cb.Checked)
ids += ",";
}

.....
iiboy 2004-08-27
  • 打赏
  • 举报
回复
你可以将CheckBox的Value值Bind到记录的唯一标识上(比如说ID字段的值)
然后
使用客户端脚本得到所有选中的ID值,再怎么处理...应该就不用说了吧!
<script language="vbscript">
dim Ids
Ids=""
for each xxobject in NewsListForm.elements
if xxobject.type="checkbox" then
if xxobject.checked then
if Ids="" then Ids=xxobject.value else Ids=Ids+","+xxobject.value
end if
end if
next
===========
Ids里面就是所有选中的ID号码集合了,ID之间使用","隔开
lyqof908 2004-08-27
  • 打赏
  • 举报
回复
以下是客户要求的页面效果:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body>
Search:文件名:
<input type="text" name="textfield">
类型:
<select name="select">
<option value="◎ 排行榜类型" selected>◎ 排行榜类型</option>
</select>
时段
<select name="select2">
<option value="月" selected>月</option>
</select>
<select name="select3">
<option value="2004年1月" selected>2004年1月</option>
</select>
<input type="submit" name="Submit" value="Submit">
<table width="75%" border="1">
<tr>
<td>服务排行</td>
</tr>
<tr>
<td><table width="100%" border="1">
<tr>
<td> </td>
<td>文件</td>
<td>类型</td>
<td>时段</td>
<td>时段值</td>
<td>发布日期</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="checkbox"></td>
<td>New*T.xsl</td>
<td>类型A</td>
<td>月</td>
<td>2004/01</td>
<td>2001-1-2 12:30</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td>营业排行</td>
</tr>
<tr>
<td><table width="100%" border="1">
<tr>
<td> </td>
<td>文件</td>
<td>类型</td>
<td>时段</td>
<td>时段值</td>
<td>发布日期</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="checkbox"></td>
<td>aa.xsl</td>
<td>类型B</td>
<td>月</td>
<td>2003/01</td>
<td>2001-1-2 12:30</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td>打字排行</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<br>
<input type="submit" name="Submit2" value="发布">
<input type="submit" name="Submit3" value="删除">
</body>
</html>

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧