我想得到这个值为一串值?

liujingbo911 2006-12-31 08:51:13
for (int i=0;i<this.DataGrid2.Items.Count;i++)
{
bool blnIfSelect = ((CheckBox)this.DataGrid2.Items[i].FindControl("chkItem")).Checked;
if (blnIfSelect == true)
{
string checkedID = this.DataGrid2.Items[i].Cells[1].Text;
}
}
这里我在DataGrid中有checkBox复选框,我想遍历看我选中了哪个,然后得到其ID值。并且我想得到的是一串值。比如,我选中了1、2、3行的checkBox,这时候我想得到这样的ID。string ID="1,2,3";请问如何得到?
...全文
112 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
liujingbo911 2006-12-31
  • 打赏
  • 举报
回复
实在惭愧!自己是个菜鸟啊!
_甲壳虫 2006-12-31
  • 打赏
  • 举报
回复

string checkedID = "";
for (int i=0;i<this.DataGrid2.Items.Count;i++)
{
bool blnIfSelect = ((CheckBox)this.DataGrid2.Items[i].FindControl("chkItem")).Checked;
if (blnIfSelect == true)
{
checkedID += "," + this.DataGrid2.Items[i].Cells[1].Text;
}
}
checkedID = checkedID.Trim(',');
yangyupeng521 2006-12-31
  • 打赏
  • 举报
回复
xrascal(横刀夺爱) 说的正确~~~

我也就奇怪了,楼主都写了那么多代码了,怎么就偏偏这点字符串不知道怎么加呢
czsxj 2006-12-31
  • 打赏
  • 举报
回复
string checkedID="";
if (blnIfSelect == true)
{
checkedID+ = this.DataGrid2.Items[i].Cells[1].Text+",";
}
暗石绿 2006-12-31
  • 打赏
  • 举报
回复
System.Text.StringBuilder sbId = new System.Text.StringBuilder();
for (int i=0;i<this.DataGrid2.Items.Count;i++)
{
bool blnIfSelect = ((CheckBox)this.DataGrid2.Items[i].FindControl("chkItem")).Checked;
if (blnIfSelect == true)
{
string checkedID = this.DataGrid2.Items[i].Cells[1].Text;
sbId.Append(checkedID+",");
}
}

if(sbId.Length>0)
{
sbId.Remove(sbId.Length-1,1);
}

// 结果:
String ID = sbId.ToString();
liujingbo911 2006-12-31
  • 打赏
  • 举报
回复
具体详细一些。
oldsongs 2006-12-31
  • 打赏
  • 举报
回复
用字符串数组定义吧
string[] checkedID

62,039

社区成员

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

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

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

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